|
-
Jun 14th, 2010, 01:53 PM
#18
Thread Starter
PowerPoster
Re: [Vb6] AlphaBlend API function(strange result)
 Originally Posted by LaVolpe
Don't think so, you may have to manually process the pixels and then use AlphaBlend:
Option 1: test it, no guarantee it will work. I don't know if TransparentBlt modifies the alpha channel on a destination 32bpp DIB/bitmap.
1. Create offscreen 32bpp DIB section & DC
2. Fill the DIB with all zeros
3. Use TransparentBLT to draw your image to that DC
4. Now use AlphaBlend to draw that DC to your control/object
5. Destroy DC & DIB at some point
Option 2
1. Must use 32bpp DIB
2. For each pixel where the RGB value should be made transparent, set its RGBA value to zero (all 4 bytes of that pixel).
3. Now use AlphaBlend API
4. Destroy DIB at some point
Option 3
Using GDI+ this can be done. Though that does mean adding GDI+ APIs to your project and learning how to load an image into GDI+, along with using GdipSetImageAttributesColorKeys, GdipSetImageAttributesColorMatrix, and several more of the GDI+ APIs.
like you see, i have 1 sub:
Code:
'how calculate the alpha values: a*rgb1 + (1-a)rgb2
Public Sub TransparentAlphaBlend(ByRef SrcPictureBox As Control, ByRef DstPictureBox As Control, ByRef Opacy As Integer, ByRef TransparentColor As Long)
Dim x As Long, y As Long
Dim lngNewColor As Long
For x = 0 To DstPictureBox.ScaleWidth - 1
For y = 0 To DstPictureBox.ScaleHeight - 1
If GetPixel(DstPictureBox.hdc, x, y) <> TransparentColor Then
lngNewColor = Opacy * GetPixel(DstPictureBox.hdc, x, y) + (1 - Opacy) * GetPixel(SrcPictureBox.hdc, x, y)
SetPixel DstPictureBox, x, y, lngNewColor
End If
Next y
Next x
End Sub
(these sub is only for test, then i will convert it to DIB's )
the problem is that i recive negative values. can you advice me?
for resolve that problem i use:
Code:
Public Sub TransparentAlphaBlend(ByRef SrcPictureBox As Control, ByRef DstPictureBox As Control, ByRef Opacy As Integer, ByRef TransparentColor As Long)
Dim X As Long, Y As Long
Dim lngNewColor As Long
Dim BF As BLENDFUNCTION, lBF As Long
With BF
.BlendOp = AC_SRC_OVER
.BlendFlags = 0
.SourceConstantAlpha = Opacy
.AlphaFormat = 0
End With
RtlMoveMemory lBF, BF, 4
For X = 0 To DstPictureBox.ScaleWidth - 1
For Y = 0 To SrcPictureBox.ScaleHeight - 1
If GetPixel(DstPictureBox.hdc, X, Y) <> TransparentColor Then
AlphaBlend SrcPictureBox.hdc, X, Y, 1, 1, DstPictureBox.hdc, X, Y, 1, 1, lBF
'lngNewColor = Opacy * GetPixel(DstPictureBox.hdc, X, Y) + (1 - Opacy) * GetPixel(SrcPictureBox.hdc, X, Y)
''SetPixel DstPictureBox, X, Y, lngNewColor
End If
Next Y
Next X
DstPictureBox.Picture = DstPictureBox.Image
End Sub
Last edited by joaquim; Jun 14th, 2010 at 01:59 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|