Here's one way to do a fade. It uses GetDIBits() to get a copy of the
picture in memory where you can manipulate the palette and SetDIBits() to
blast the result back to the screen: it's pretty fast for reasonable-size
bitmaps (not sure about fullscreen!). This routine is intrinsically
16-color, but you could alter it to 256-color (roughly half as fast) or
24-bit color (_way_ slower). Anyway, it may give you a starting point.
Note that it does not _realize_ the palette, so if you want it to run in
256-color video (forget it in 16-color) you'll have to realize an
appropriate palette yourself.
It's got a slightly clever method of making the fade speed somewhat
independent of the machine speed by doing the fade in four parts, timing
each one, and adjusting on the fly.
Jim Deutch
MS Dev MVP
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPel{*filter*}eter As Long
biYPel{*filter*}eter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO_4
bmiHeader As BITMAPINFOHEADER
bmiColors(15) As RGBQUAD
End Type
Private Const PIXEL As Integer = 3
Private Const DIB_RGB_COLORS As Long = 0
Private Declare Function GetDIBits4 Lib "gdi32" Alias "GetDIBits" _
(ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _
ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO_4, _
ByVal wUsage As Long) As Long
Private Declare Function SetDIBits4 Lib "gdi32" Alias "SetDIBits" (ByVal
hdc As Long, _
ByVal hBitmap As Long, ByVal nStartScan As Long, _
ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO_4, _
ByVal wUsage As Long) As Long
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)
Static SaveBits() As Byte
Static SaveBitmapInfo_4 As BITMAPINFO_4
Static nLen As Long
Static Start As Single
Static SubIters As Long
Static nName As Long
Static y As Long
Dim BufferSize As Long
Dim retval As Long
Dim i As Long
Dim cFace As Long
Dim R As Long, G As Long, B As Long
Static x As Long
Static j As Single
Dim Level As Long
Static picSrcDC As Long
Static frmDC As Long
Static picSrcLeft As Long
Static picSrcTop As Long
Static picSrcWidth As Long
Static picSrcHeight As Long
'realize the palette
picpal.ZOrder
'size a buffer for the pixel data
BufferSize = ((picSrc.ScaleWidth / 2 + 3) And &HFFFC) *
picSrc.ScaleHeight
ReDim SaveBits(0 To BufferSize - 1) 'As Byte
'fill the header info for the save copy
With SaveBitmapInfo_4.bmiHeader
.biSize = 40
.biWidth = picSrc.ScaleWidth
.biHeight = picSrc.ScaleHeight
.biPlanes = 1
.biBitCount = 4
.biCompression = 0
.biClrUsed = 0
.biClrImportant = 0
.biSizeImage = BufferSize
End With
nLen = Len(SaveBitmapInfo_4)
'get the bitmap from the picturebox
retval = GetDIBits4(picSrc.hdc, picSrc.Image, 0, _
SaveBitmapInfo_4.bmiHeader.biHeight, SaveBits(0),
SaveBitmapInfo_4, DIB_RGB_COLORS)
'cache stuff
picSrcDC = picSrc.hdc
frmDC = Me.hdc
picSrcLeft = picSrc.Left ' / Screen.TwipsPerPixelX
picSrcTop = picSrc.Top ' / Screen.TwipsPerPixelY
picSrcWidth = picSrc.ScaleWidth
picSrcHeight = picSrc.ScaleHeight
'fade in the logo
For i = 0 To 4
Start = Timer
'change the palette
j = 0
Do
j = j + Incr
Level = i * 51 + j
If Level > 255 Then Exit Do
SaveBitmapInfo_4.bmiColors(4).rgbBlue = Level / 2
SaveBitmapInfo_4.bmiColors(15).rgbBlue = Level
SaveBitmapInfo_4.bmiColors(15).rgbRed = Level
SaveBitmapInfo_4.bmiColors(15).rgbGreen = Level
'blast it back into the picturebox
retval = SetDIBits4(picSrcDC, picSrc.Image.handle, 0, _
SaveBitmapInfo_4.bmiHeader.biHeight, SaveBits(0),
SaveBitmapInfo_4, DIB_RGB_COLORS)
'transfer it to the form
retval = BitBlt(frmDC, picSrcLeft, picSrcTop, _
picSrcWidth, picSrcHeight, picSrcDC, 0, 0, SRCCOPY)
Loop While j < 52
If Timer - Start = 0 Then
Incr = Incr / 2
Else
Incr = Incr / (SECONDS_FADE_LOGO / 5 / (Timer - Start))
End If
Next i
Quote:
> Is there any way to change a pictures brightness through code (aka fade
the
> picture) without using a custom control?
> -Dan