can I alpha blend a image or picturebox control to what ever is behind it?
Printable View
can I alpha blend a image or picturebox control to what ever is behind it?
Yes if you know what's behind it in the first place
How?
For each pixel, you can average the red, green and blue components of the colour, using the ratio of the two alphas as a bias, so it's a weighted average.
Or for alpha channels involved, multiply soruce component with alpha, and add target component multiplied by 1-alpha
Most of us know this, but:
HOW do you alpha-blend with a good framerate? Must you use GetObject and Get and Set Bitmap Bits? Or is there a DLL out there that returns an hDC or something?
If there is, I'm sure we'd all like to know!
DMA is the answer, have a look at them at http://www.ur.co.nz/ and check out the DMA samples that uses array pointers to manipulate bitmaps directly. Calling a C++ dll would be a lot faster though, if anyone have this i'd like to know.
Why not using the AlphaBlend function????
Here's the code taken from API Guide:
Code:'This project requires two picture boxes
'Both picture boxes should contain a picture
Private Type BLENDFUNCTION
BlendOp As Byte
BlendFlags As Byte
SourceConstantAlpha As Byte
AlphaFormat As Byte
End Type
Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim BF As BLENDFUNCTION, lBF As Long
'Set the graphics mode to persistent
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
'API uses pixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
'set the parameters
With BF
.BlendOp = AC_SRC_OVER
.BlendFlags = 0
.SourceConstantAlpha = 128
.AlphaFormat = 0
End With
'copy the BLENDFUNCTION-structure to a Long
RtlMoveMemory lBF, BF, 4
'AlphaBlend the picture from Picture1 over the picture of Picture2
AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
End Sub
lInt, lInt, lInt... ARGH!
The programmer must've gotten kinda bored on that one.
THANK YOU VERY MUCH!
Thank you, Arcom!!!
That saved me! Since it uses hDCs, I can also use it for DDRAW! BRILLIANT!
Thank you Arcom, thank you!
Nice code Arcom, I'll look at it later when I got time.
just 1 thing: AlphaBlend isn't supported on Win95, so you'd have to distribute the new version of msimg32.dll with your app