Пример #1
0
        public static Graphics AlphaBlend(this Graphics gr, Bitmap b, Rectangle to, Rectangle from, float opacity)
        {
            #if WINCE
            byte bopacity = unchecked((byte)(255 * opacity));

            using (Graphics gxSrc = Graphics.FromImage(b))
            {
              IntPtr hdcDst = gr.GetHdc();
              IntPtr hdcSrc = gxSrc.GetHdc();
              BlendFunction blendFunction = new BlendFunction();
              blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER;
              blendFunction.BlendFlags = (byte)BlendFlags.Zero;
              blendFunction.SourceConstantAlpha = bopacity;
              blendFunction.AlphaFormat = (byte)0;
              try{
                  PlatformAPI.AlphaBlend(hdcDst, to.X, to.Y, to.Width, to.Height, hdcSrc, from.X, from.Y, from.Width, from.Height, blendFunction);
              }catch(Exception e){}
              gr.ReleaseHdc(hdcDst);
              gxSrc.ReleaseHdc(hdcSrc);
            }
            #else
            var ia = new ImageAttributes();
            float[][] ptsArray = {
                        new float[] {1, 0, 0, 0, 0},
                        new float[] {0, 1, 0, 0, 0},
                        new float[] {0, 0, 1, 0, 0},
                        new float[] {0, 0, 0, opacity, 0},
                        new float[] {0, 0, 0, 0, 1}};
            ia.SetColorMatrix(new ColorMatrix(ptsArray));
            gr.DrawImage(b, to, from.X, from.Y, from.Width, from.Height, GraphicsUnit.Pixel, ia);
            #endif
            return gr;
        }
Пример #2
0
        public static Graphics AlphaBlend(this Graphics gr, Bitmap b, Rectangle to, Rectangle from, float opacity)
        {
#if WINCE
            byte bopacity = unchecked ((byte)(255 * opacity));

            using (Graphics gxSrc = Graphics.FromImage(b))
            {
                IntPtr        hdcDst        = gr.GetHdc();
                IntPtr        hdcSrc        = gxSrc.GetHdc();
                BlendFunction blendFunction = new BlendFunction();
                blendFunction.BlendOp             = (byte)BlendOperation.AC_SRC_OVER;
                blendFunction.BlendFlags          = (byte)BlendFlags.Zero;
                blendFunction.SourceConstantAlpha = bopacity;
                blendFunction.AlphaFormat         = (byte)0;
                try{
                    PlatformAPI.AlphaBlend(hdcDst, to.X, to.Y, to.Width, to.Height, hdcSrc, from.X, from.Y, from.Width, from.Height, blendFunction);
                }catch (Exception e) {}
                gr.ReleaseHdc(hdcDst);
                gxSrc.ReleaseHdc(hdcSrc);
            }
#else
            var       ia       = new ImageAttributes();
            float[][] ptsArray =
            {
                new float[] { 1, 0, 0,       0, 0 },
                new float[] { 0, 1, 0,       0, 0 },
                new float[] { 0, 0, 1,       0, 0 },
                new float[] { 0, 0, 0, opacity, 0 },
                new float[] { 0, 0, 0,       0, 1 }
            };
            ia.SetColorMatrix(new ColorMatrix(ptsArray));
            gr.DrawImage(b, to, from.X, from.Y, from.Width, from.Height, GraphicsUnit.Pixel, ia);
#endif
            return(gr);
        }
Пример #3
0
 public static extern Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32 yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32 ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction);
Пример #4
0
 extern public static Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32 yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32 ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction);