public static void FillRectangleAlpha(Graphics graphic, Brush brush, int left, int top, int width, int height, int transparency) { if (_workGraphics == null) { _workBitmap = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); _workGraphics = Graphics.FromImage(_workBitmap); } _workGraphics.FillRectangle(brush, 0, 0, width, height); PlatformAPIs.DrawAlpha(graphic, _workBitmap, (byte)transparency, left, top, width, height); }
public static void DrawAlpha(Graphics gx, Bitmap image, byte transp, int x, int y, int width, int height) { using (Graphics gxSrc = Graphics.FromImage(image)) { IntPtr hdcDst = gx.GetHdc(); IntPtr hdcSrc = gxSrc.GetHdc(); BlendFunction blendFunction = new BlendFunction(); blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER; // Only supported blend operation blendFunction.BlendFlags = (byte)BlendFlags.Zero; // Documentation says put 0 here blendFunction.SourceConstantAlpha = transp; // Constant alpha factor blendFunction.AlphaFormat = (byte)0; // Don't look for per pixel alpha PlatformAPIs.AlphaBlend(hdcDst, x, y, width, height, hdcSrc, 0, 0, width, height, blendFunction); gx.ReleaseHdc(hdcDst); // Required cleanup to GetHdc() gxSrc.ReleaseHdc(hdcSrc); // Required cleanup to GetHdc() } }