Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
alphablend (gdi32)
 
.
Summary
This function displays bitmaps that have transparent or semitransparent pixels on Microsoft Mobile Os'es

C# Signature:

[DllImport("gdi32.dll", EntryPoint="GdiAlphaBlend")]
public static extern bool AlphaBlend(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,
    int nWidthDest, int nHeightDest,
    IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
    BLENDFUNCTION blendFunction);

VB Signature:

Public Declare Function AlphaBlend Lib "gdi32.dll" Alias "GdiAlphaBlend"
    (ByVal hdcDest As IntPtr, ByVal nXOriginDest As Integer, ByVal nYOriginDest As Integer,
    ByVal nWidthDest As Integer, ByVal nHeightDest As Integer,
    ByVal hdcSrc As IntPtr, ByVal nXOriginSrc As Integer, ByVal nYOriginSrc As Integer,
    ByVal nWidthSrc As Integer, ByVal nHeightSrc As Integer,
    ByVal blendFunction As BLENDFUNCTION) As Boolean

User-Defined Types:

BLENDFUNCTION

[StructLayout(LayoutKind.Sequential)]
public struct BLENDFUNCTION
{
    byte BlendOp;
    byte BlendFlags;
    byte SourceConstantAlpha;
    byte AlphaFormat;

    public BLENDFUNCTION(byte op, byte flags, byte alpha, byte format)
    {
    BlendOp = op;
    BlendFlags = flags;
    SourceConstantAlpha = alpha;
    AlphaFormat = format;
    }
}

//
// currently defined blend operation
//
const int AC_SRC_OVER = 0x00;

//
// currently defined alpha format
//
const int AC_SRC_ALPHA = 0x01;

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

[DllImport("gdi32.dll", EntryPoint = "GdiAlphaBlend")]
public static extern bool AlphaBlend(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,
   int nWidthDest, int nHeightDest,
   IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
   BLENDFUNCTION blendFunction);

[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth,
   int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc,  TernaryRasterOperations dwRop);    

[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern bool DeleteDC(IntPtr hdc);

[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern bool DeleteObject(IntPtr hObject);

[StructLayout(LayoutKind.Sequential)]
public struct BLENDFUNCTION
{
   byte BlendOp;
   byte BlendFlags;
   byte SourceConstantAlpha;
   byte AlphaFormat;

   public BLENDFUNCTION(byte op, byte flags, byte alpha, byte format)
   {
     BlendOp = op;
     BlendFlags = flags;
     SourceConstantAlpha = alpha;
     AlphaFormat = format;
   }
}

const byte AC_SRC_OVER = 0x00;
const byte AC_SRC_ALPHA = 0x01;

protected override void OnPaint(PaintEventArgs e) {
    IntPtr pTarget = e.Graphics.GetHdc();
    IntPtr pSource = CreateCompatibleDC(pTarget);
    IntPtr pOrig = SelectObject(pSource, bmp.GetHbitmap(Color.Black));
    AlphaBlend(pTarget, 0, 0, bmp.Width, bmp.Height, pSource, 0, 0, bmp.Width, bmp.Height, new BLENDFUNCTION(AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA));
    IntPtr pNew = SelectObject(pSource, pOrig);
    DeleteObject(pNew);
    DeleteDC(pSource);
    e.Graphics.ReleaseHdc(pTarget);
}

Documentation
AlphaBlend on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions