i'm trying doing\simulate a real Opacity in controls(usercontrol). and works better than i thot
but the problem is that i see a flicker when draw the image and i don't understand how fix that
i try the doublem buffering and the results aren't correct
pseudo code:
1 - clean usercontrol(the original image is in picture1);
2 - clean picture2. for recive the parent\container capture(that's why i need clean the user control, for hide it and capture what is in back);
3 - by some reason i MUST use the doevents() for the usercontrol been realy clean(or isn't clean);
4 - now i use the bitblt() for capture the container and put it in picture2:
Code:
Public Sub CaptureContainer(ByVal DestinationHDC As Long, ByVal SourceHWND As Long, ByVal SourceX As Long, ByVal SourceY As Long, ByVal SourceWidth As Long, ByVal SourceHeight As Long)
Dim SourceDC As Long
SourceDC = GetDC(SourceHWND)
BitBlt DestinationHDC, 0, 0, SourceWidth, SourceHeight, SourceDC, SourceX, SourceY, vbSrcCopy
End Sub
5 - now i combine the pixels for do the opacity(i must use these sub for transparency):
Code:
Public Sub TransparentAlphaBlend(ByRef SrcHDC As Long, _
ByRef DstHDC As Long, _
ByRef SrcWidth As Integer, _
ByRef SrcHeight As Integer, _
ByRef Opacity As Integer, _
ByRef TransparentColor As Long)
Dim x As Long, y As Long
Dim lngsrcColor As Long, lngdstColor As Long, lngNewColor As Long
Dim lngAlpha As Long, R As Long, G As Long, B As Long
Dim SrcRed As Long, SrcBlue As Long, SrcGreen As Long
Dim DstRed As Long, DstBlue As Long, DstGreen As Long
'convert the values from 0-100 to 0-255
lngAlpha = Opacity * 255 / 100
For x = 0 To SrcWidth - 1
For y = 0 To SrcHeight - 1
'geting the source and destination colors\pixels
lngdstColor = GetPixel(DstHDC, x, y)
lngsrcColor = GetPixel(SrcHDC, x, y)
'if source pixel is tranparentcolor then ignore it
If lngsrcColor <> TransparentColor Then
'geting the destinations RGB values
DstRed = lngdstColor And 255
DstGreen = (lngdstColor And 65535) \ 256
DstBlue = (lngdstColor And &HFF0000) \ 65536
'geting the source destination RGB values
SrcRed = lngsrcColor And 255
SrcGreen = (lngsrcColor And 65535) \ 256
SrcBlue = (lngsrcColor And &HFF0000) \ 65536
'FinalPixel = (AlphaValue * (Source + 256 - Destination)) / 256 + Destination - AlphaValue
'now i must combine them with alpha values for make the opacy\fade
R = (lngAlpha * (SrcRed + 256 - DstRed)) / 256 + DstRed - lngAlpha
G = (lngAlpha * (SrcGreen + 256 - DstGreen)) / 256 + DstGreen - lngAlpha
B = (lngAlpha * (SrcBlue + 256 - DstBlue)) / 256 + DstBlue - lngAlpha
lngNewColor = RGB(R, G, B)
'now that i have the new color, i use it
SetPixelV DstHDC, x, y, lngNewColor
End If
Next y
Next x
End Sub
and the result is puted in picture2;
5 - now i draw the results in usercontrol.
with:
1 - doublebuffer i still see the flicker and bad results(just like black rectangules);
2 - with that sub or my DIB's sub i have good results, but a flicker
any advice please?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.