I am trying to use the WM5 AlphaBlend() function to add transparency to an image. I found this link that contains a great example in C#.
http://blogs.msdn.com/chrislorton/archive/2006/04/07/570649.aspx#571734
When I download and run the C# example it works fine. I converted it to VB , but now the image does not display. I don't get any errors returned, but nothing is drawn.
Here is my code. Any help would be appreciated.
Imports
System.ReflectionPublic
Class Form4 'Dim constantAlphaImage As Bitmap Dim constantAlphaImage As ImageProtected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
' Load the image to use with the AlphaBlend API.
Dim path As String = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)constantAlphaImage =
New Bitmap(path + "\blendme.bmp") ' AlphaBlend takes two HDC's - one source and one destination. Here's the source. Using gxSrc As Graphics = Graphics.FromImage(constantAlphaImage) Dim hdcDst As IntPtr = e.Graphics.GetHdc() Dim hdcSrc As IntPtr = gxSrc.GetHdc() Dim blendFunction As New BlendFunction()blendFunction.BlendOp =
CByte(BlendOperation.AC_SRC_OVER) ' Only supported blend operationblendFunction.BlendFlags =
CByte(BlendFlags.Zero) ' Documentation says put 0 hereblendFunction.SourceConstantAlpha =
CByte(128) ' Constant alpha factorblendFunction.AlphaFormat =
CByte(0) ' Don't look for per pixel alphaPlatformAPIs.AlphaBlend(hdcDst, Left, Top, Width, Height, hdcSrc, _
0, 0, Width, Height, blendFunction)
gxSrc.ReleaseHdc(hdcSrc)
' Required cleanup to GetHdc() ' Required cleanup to GetHdc()e.Graphics.ReleaseHdc(hdcDst)
End Using End SubEnd
ClassImports
SystemImports
System.Collections.GenericImports
System.TextImports
System.Runtime.InteropServicesPublic Structure BlendFunction
Public BlendOp As Byte
Public BlendFlags As Byte Public SourceConstantAlpha As Byte Public AlphaFormat As Byte End Structure Public Enum BlendOperation As ByteAC_SRC_OVER = 0
End Enum Public Enum BlendFlags As ByteZero = 0
End Enum Public Enum SourceConstantAlpha As ByteTransparent = 0
Opaque = 255
End Enum Public Enum AlphaFormat As ByteAC_SRC_ALPHA = 1
End EnumPublic Class PlatformAPIs
<DllImport(
"coredll.dll")> _ Public Shared Function AlphaBlend(ByVal hdcDest As IntPtr, ByVal xDest As Int32, ByVal yDest As Int32, ByVal cxDest As Int32, ByVal cyDest As Int32, ByVal hdcSrc As IntPtr, _ ByVal xSrc As Int32, ByVal ySrc As Int32, ByVal cxSrc As Int32, ByVal cySrc As Int32, ByVal blendFunction As BlendFunction) As Int32 End FunctionEnd
Class