how can i add a color key with AlphaBlend() API function?
(some backgorund colors aren't transparent, so the transparent(color key and not alpha) don't works)
how can i add a color key with AlphaBlend() API function?
(some backgorund colors aren't transparent, so the transparent(color key and not alpha) don't works)
I don't think you can do color keying with AlphaBlend(), at least not without an alpha channel.
Perhaps you are looking for TransparentBlt.
HTH
That makes little sense, why would there be a need for keying if you have full alpha at your disposal?
Perhaps you haven't provided enough details about what you're trying to do or the over all situation.
I don't know how to do it with the API that you're using (it sounds like VB6) but in SFML, the sf::Image class contains a method called CreateMaskFromColor() that you can use on a loaded image. You can then use that sf::Image to create an sf::Sprite and then later use sf::Sprite::setColor() to modulate the color and the alpha of the sprite before it's blt to its destination.
i have 2 diferent images:
- the 1st(have a transparent backcolor): i can draw it transparent and with alpha... great;
- the 2nd(don't have a transparent backcolor): i can draw it not transparent and with alpha.
both images are a gif files
why these conclusion between the 2 images?
almost fixed:
Public Sub Draw(DestinationHDC As Long, blnTransparent As Boolean, Optional Transparency As Long = 255)
RaiseEvent BeforeDrawImage(intSelectedFrame)
Dim AO As AlphaOptions
Dim PointerAlpha As Long
If (blnTransparent = True) Then
Dim color As Long
Dim btMap As BITMAP
If (GetObject(ImageBitmap, Len(btMap), btMap) = 0) Then Debug.Print "error"
Dim s As BITMAPINFO
Dim BytesPerScanLine As Long
s.bmiHeader.biSize = 40
s.bmiHeader.biPlanes = 1
s.bmiHeader.biBitCount = 24
s.bmiHeader.biHeight = -lngheight
s.bmiHeader.biWidth = lngwidth
s.bmiHeader.biPlanes = btMap.bmPlanes
s.bmiHeader.biCompression = 0
BytesPerScanLine = ((Abs(s.bmiHeader.biWidth) * 3) + 3) And &HFFFFFFFC
s.bmiHeader.biSizeImage = BytesPerScanLine * lngheight
Dim ImageData() As Byte
ReDim ImageData(3, s.bmiHeader.biWidth, lngheight)
GetDIBits ImageHDC, ImageBitmap, 0, lngheight, ImageData(0, 0, 0), s, 0
If ((((color And &HFF000000) \ 16777216) And &HFF) <> 255) Then
Dim x As Long
Dim y As Long
For y = 0 To lngheight - 1
For x = 0 To lngwidth - 1
color = GetPixel(ImageHDC, x, y)
If (color = GetPixel(ImageHDC, 0, 0)) Then
'Debug.Print "changing alpha pixels "
color = RGBA(color, 0)
SetPixel ImageHDC, x, y, color
End If
Next x
Next y
End If
AO.AlphaFlags = 0
AO.AlphaFormat = AC_SRC_ALPHA
AO.AlphaOption = AC_SRC_OVER
AO.SourceConstantAlpha = Transparency
RtlMoveMemory PointerAlpha, AO, 4
AlphaBlend DestinationHDC, 0, 0, lngwidth, lngheight, ImageHDC, 0, 0, lngwidth, lngheight, PointerAlpha
Else
AO.AlphaFlags = 0
AO.AlphaFormat = 0 'AC_SRC_ALPHA
AO.AlphaOption = AC_SRC_OVER
AO.SourceConstantAlpha = Transparency
RtlMoveMemory PointerAlpha, AO, 4
AlphaBlend DestinationHDC, 0, 0, lngwidth, lngheight, ImageHDC, 0, 0, lngwidth, lngheight, PointerAlpha
End If
End Sub
i'm getting trouble on getting the alpha values.
can anyone correct me how can i calculate the alpha on pixel?
(yes, for now, i'm using GetPixel() and SetPixel(). they are very slow. but for now i need test the alpha value correctly)
the:
(((color And &HFF000000) \ 16777216) And &HFF)
give me always zero :(
You haven't initialized color to anything by the time it's gotten to the condition you asked about.
Also, I'm not sure on whether GetPixel includes an alpha value. I haven't looked extensively but this documentation suggests that maybe the alpha value isn't included. I'd recommend maybe checking by setting a pixel at a know location to something with an alpha value you know and verify the get returns that value as expected.
i have 2 diferent images: - the 1st(have a transparent backcolor): i can draw it transparent and with alpha... great; - the 2nd(don't have a transparent backcolor): i can draw it not transparent and with alpha. both images are a gif files why these conclusion between the 2 images?
If they were files that were provided to you from someone else, it could depend on how the gif images were created and saved. I'd recommend converting them to a format or recreating the files so you're confident that they have the alpha value saved with them.