Click to See Complete Forum and Search --> : Fading a picture


December 9th, 1999, 10:45 AM
How can I fade a PictureBox or ImageBox without flicker?

It would have to be able to fade multiple colors at one time, obviously.

Thanks.

December 9th, 1999, 04:36 PM
i would know how to fade it pixel by pixel...but that would be way too slow...
you might look into the directX (directdraw & direct animation) sdks for this.

December 10th, 1999, 07:27 AM
Well, the DX SDKs are around 128 MB (unless I missed something here) and I can only use the Net at my school.

When I used to use QB4.5, I could fade good in there. It wasn't slow or too hard. It should be just as easy in VB, and faster.

Thanks though.

Monstrum
January 14th, 2000, 09:12 AM
Yes, that's because QB uses indexed colors and just changes the palette.
You can use DirectX and do it pixel by pixel, that should work and it should be pretty fast also.
This doesn't work with the BitBlt API call (Actually, do NOT use this API at all if it is not really, really nescesary)

Aaron Young
January 14th, 2000, 09:43 AM
Try something like this:

private Declare Function BitBlt Lib "gdi32" (byval hDestDC as Long, byval x as Long, byval y as Long, byval nWidth as Long, byval nHeight as Long, byval hSrcDC as Long, byval xSrc as Long, byval ySrc as Long, byval dwRop as Long) as Long
private Declare Function CreateCompatibleDC Lib "gdi32" (byval hdc as Long) as Long
private Declare Function CreateCompatibleBitmap Lib "gdi32" (byval hdc as Long, byval nWidth as Long, byval nHeight as Long) as Long
private Declare Function DeleteDC Lib "gdi32" (byval hdc as Long) as Long
private Declare Function DeleteObject Lib "gdi32" (byval hObject as Long) as Long
private Declare Function SelectObject Lib "gdi32" (byval hdc as Long, byval hObject as Long) as Long
private Declare Sub Sleep Lib "kernel32" (byval dwMilliseconds as Long)

private Const SRCAND = &H8800C6
private Const SRCCOPY = &HCC0020

private Sub Command1_Click()
Dim lDC as Long
Dim lBMP as Long
Dim W as Integer
Dim H as Integer
Dim lColor as Long

W = ScaleX(Picture1.Picture.Width, vbHimetric, vbPixels)
H = ScaleY(Picture1.Picture.Height, vbHimetric, vbPixels)
lBMP = CreateCompatibleBitmap(Picture1.hdc, W, H)
lDC = CreateCompatibleDC(Picture1.hdc)
Call SelectObject(lDC, lBMP)
BitBlt lDC, 0, 0, W, H, Picture1.hdc, 0, 0, SRCCOPY
Picture1 = LoadPicture("")
for lColor = 255 to 0 step -3
Picture1.BackColor = RGB(lColor, lColor, lColor)
BitBlt Picture1.hdc, 0, 0, W, H, lDC, 0, 0, SRCAND
Sleep 10
next
Call DeleteDC(lDC)
Call DeleteObject(lBMP)
End Sub





Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com