public static void DrawAlpha(this Graphics g, Image image, byte transparency, int x, int y)
        {
            using (var gSrc = Graphics.FromImage(image))
            {
                var hdcDst = g.GetHdc();
                var hdcSrc = gSrc.GetHdc();

                var blendFunction = new BlendFunction
                {
                    BlendOp             = 0x00, // AC_SRC_OVER
                    BlendFlags          = 0x00,
                    SourceConstantAlpha = transparency,
                    AlphaFormat         = 0
                };
                NativeMethods.AlphaBlend(hdcDst, x, y, image.Width, image.Height, hdcSrc, 0, 0, image.Width, image.Height, blendFunction);

                g.ReleaseHdc(hdcDst);
                gSrc.ReleaseHdc(hdcSrc);
            }
        }
Beispiel #2
0
 internal static extern bool AlphaBlend(IntPtr hdcDest, int xDest, int yDest, int cxDest, int cyDest, IntPtr hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, BlendFunction blendFunction);
        public static void DrawAlpha(this Graphics g, Image image, byte transparency, int x, int y)
        {
            using (var gSrc = Graphics.FromImage(image))
            {
                var hdcDst = g.GetHdc();
                var hdcSrc = gSrc.GetHdc();

                var blendFunction = new BlendFunction
                {
                    BlendOp = 0x00, // AC_SRC_OVER
                    BlendFlags = 0x00,
                    SourceConstantAlpha = transparency,
                    AlphaFormat = 0
                };
                NativeMethods.AlphaBlend(hdcDst, x, y, image.Width, image.Height, hdcSrc, 0, 0, image.Width, image.Height, blendFunction);

                g.ReleaseHdc(hdcDst);
                gSrc.ReleaseHdc(hdcSrc);
            }
        }
 internal static extern bool AlphaBlend(IntPtr hdcDest, int xDest, int yDest, int cxDest, int cyDest, IntPtr hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, BlendFunction blendFunction);