コード例 #1
0
ファイル: AlphaImage.cs プロジェクト: SeregaPru/metrohome65
        public static void DrawAlphaImage(Graphics g, Image img, Rectangle rect, byte alpha)
        {
            var hdcDst = g.GetHdc();
            var gSrc = Graphics.FromImage(img);
            var hdcSrc = gSrc.GetHdc();

            var blendFunction = new BlendFunction
                                    {
                                        BlendOp = (byte) BlendOperation.AcSrcOver,
                                        BlendFlags = (byte) BlendFlags.Zero,
                                        SourceConstantAlpha = alpha,
                                        AlphaFormat = 0
                                    };
            // Only supported blend operation
            // Documentation says put 0 here
            // Constant alpha factor
            // AlphaFormat.AC_SRC_ALPHA;
            //!!blendFunction.AlphaFormat = (byte)AlphaFormat.AC_SRC_ALPHA;

            DrawingAPI.AlphaBlend(hdcDst, rect.Left, rect.Top, rect.Width, rect.Height, hdcSrc,
                0, 0, img.Width, img.Height, blendFunction);

            g.ReleaseHdc(hdcDst);          // Required cleanup to GetHdc()
            gSrc.ReleaseHdc(hdcSrc);       // Required cleanup to GetHdc()
        }
コード例 #2
0
ファイル: AlphaImage.cs プロジェクト: SeregaPru/metrohome65
        public void PaintBackgroundAlpha(Graphics g, Rectangle rect, byte alpha)
        {
            //!! see _factory.CreateBitmapFromImage

            var buffer = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            var buffergx = Graphics.FromImage(buffer);

            var bufferRect = new Rectangle(0, 0, rect.Width, rect.Height);
            if (_img == null) return;

            var hdcBuffer = buffergx.GetHdc();
            try
            {
                OpenNETCF.Drawing.Imaging.RECT imgRect = OpenNETCF.Drawing.Imaging.RECT.FromXYWH(
                    bufferRect.Left, bufferRect.Top, bufferRect.Width, bufferRect.Height);
                _img.Draw(hdcBuffer, imgRect, null);
                buffergx.ReleaseHdc(hdcBuffer);
            }
            catch
            { }

            var hdcDst = g.GetHdc();
            hdcBuffer = buffergx.GetHdc();
            var blendFunction = new BlendFunction
                                    {
                                        BlendOp = (byte) BlendOperation.AcSrcOver,
                                        BlendFlags = (byte) BlendFlags.Zero,
                                        SourceConstantAlpha = alpha,
                                        AlphaFormat = (byte) AlphaFormat.AcSrcAlpha
                                    };
            // Only supported blend operation
            // Documentation says put 0 here
            // Constant alpha factor

            DrawingAPI.AlphaBlend(hdcDst, rect.Left, rect.Top, rect.Width, rect.Height, hdcBuffer,
                                  0, 0, rect.Width, rect.Height, blendFunction);

            g.ReleaseHdc(hdcDst);          // Required cleanup to GetHdc()
            buffergx.ReleaseHdc(hdcBuffer);       // Required cleanup to GetHdc()
        }
コード例 #3
0
ファイル: AlphaImage.cs プロジェクト: SeregaPru/metrohome65
        public void PaintBackgroundAlpha(Graphics g, Rectangle Rect, byte Alpha)
        {
            //!! see _factory.CreateBitmapFromImage

            Bitmap buffer = new Bitmap(Rect.Width, Rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            Graphics buffergx = Graphics.FromImage(buffer);
            IntPtr hdcBuffer;

            Rectangle BufferRect = new Rectangle(0, 0, Rect.Width, Rect.Height);
            if (_img != null)
            {
                hdcBuffer = buffergx.GetHdc();
                try
                {
                    OpenNETCF.Drawing.Imaging.RECT ImgRect = OpenNETCF.Drawing.Imaging.RECT.FromXYWH(
                        BufferRect.Left, BufferRect.Top, BufferRect.Width, BufferRect.Height);
                    _img.Draw(hdcBuffer, ImgRect, null);
                    buffergx.ReleaseHdc(hdcBuffer);
                }
                catch (Exception e) { }

                IntPtr hdcDst = g.GetHdc();
                hdcBuffer = buffergx.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 = Alpha;                 // Constant alpha factor
                blendFunction.AlphaFormat = (byte)AlphaFormat.AC_SRC_ALPHA;

                DrawingAPI.AlphaBlend(hdcDst, Rect.Left, Rect.Top, Rect.Width, Rect.Height, hdcBuffer,
                    0, 0, Rect.Width, Rect.Height, blendFunction);

                g.ReleaseHdc(hdcDst);          // Required cleanup to GetHdc()
                buffergx.ReleaseHdc(hdcBuffer);       // Required cleanup to GetHdc()
            }
        }
コード例 #4
0
ファイル: AlphaImage2.cs プロジェクト: SeregaPru/metrohome65
 public static extern bool AlphaBlend(IntPtr hdcDest, Int32 nXDest, Int32 nYDest, Int32 nWidthDst, Int32 nHeightDst, IntPtr hdcSrc, Int32 nXSrc, Int32 nYSrc, Int32 nWidthSrc, Int32 nHeightSrc, BlendFunction blendFunction);
コード例 #5
0
ファイル: AlphaImage.cs プロジェクト: SeregaPru/metrohome65
        public static void DrawAlphaImage(Graphics g, Image Img, Rectangle Rect, byte Alpha)
        {
            IntPtr hdcDst = g.GetHdc();
            Graphics gSrc = Graphics.FromImage(Img);
            IntPtr hdcSrc = gSrc.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 = Alpha;                 // Constant alpha factor
            blendFunction.AlphaFormat = (byte)0; // AlphaFormat.AC_SRC_ALPHA;
            //!!blendFunction.AlphaFormat = (byte)AlphaFormat.AC_SRC_ALPHA;

            DrawingAPI.AlphaBlend(hdcDst, Rect.Left, Rect.Top, Rect.Width, Rect.Height, hdcSrc,
                0, 0, Img.Width, Img.Height, blendFunction);

            g.ReleaseHdc(hdcDst);          // Required cleanup to GetHdc()
            gSrc.ReleaseHdc(hdcSrc);       // Required cleanup to GetHdc()
        }