Ejemplo n.º 1
0
 public virtual void UpdateWindow(Bitmap bitmap, double opacity)
 {
     if (bitmap == null)
     {
         return;
     }
     if (Image.IsCanonicalPixelFormat(bitmap.PixelFormat) && Image.IsAlphaPixelFormat(bitmap.PixelFormat))
     {
         IntPtr zero = IntPtr.Zero;
         IntPtr dC   = NativeMethods.GetDC(IntPtr.Zero);
         IntPtr hObj = IntPtr.Zero;
         IntPtr hDC  = NativeMethods.CreateCompatibleDC(dC);
         try
         {
             Point pptDst = new Point(base.Left, base.Top);
             Size  psize  = new Size(bitmap.Width, bitmap.Height);
             Struct.BLENDFUNCTION pblend = new Struct.BLENDFUNCTION();
             Point pptSrc = new Point(0, 0);
             hObj                       = bitmap.GetHbitmap(Color.FromArgb(0));
             zero                       = NativeMethods.SelectObject(hDC, hObj);
             pblend.BlendOp             = 0;
             pblend.SourceConstantAlpha = (byte)((int)(255.0 * opacity));
             pblend.AlphaFormat         = 1;
             pblend.BlendFlags          = 0;
             NativeMethods.UpdateWindow(base.Handle, dC, ref pptDst, ref psize, hDC, ref pptSrc, 0, ref pblend, 2);
             return;
         }
         finally
         {
             if (hObj != IntPtr.Zero)
             {
                 NativeMethods.SelectObject(hDC, zero);
                 NativeMethods.DeleteObject(hObj);
             }
             NativeMethods.ReleaseDC(IntPtr.Zero, dC);
             NativeMethods.DeleteDC(hDC);
         }
     }
     throw new ApplicationException("图片必须是32位带Alhpa通道的图片。");
 }
Ejemplo n.º 2
0
 private void method_0(IntPtr intptr_0, ref Point point_0, ref Size size_0, IntPtr intptr_1, ref Point point_1, ref Struct.BLENDFUNCTION blendfunction_0)
 {
     NativeMethods.UpdateWindow(base.Handle, intptr_0, ref point_0, ref size_0, intptr_1, ref point_1, 0, ref blendfunction_0, 2);
 }