110,536
社区成员
发帖
与我相关
我的任务
分享
Bitmap bitmap = (Bitmap)img;
IntPtr hObject = IntPtr.Zero;
IntPtr zero = IntPtr.Zero;
IntPtr hDC = Win32.GetDC(IntPtr.Zero);
IntPtr ptr2 = Win32.CreateCompatibleDC(hDC);
hObject = bitmap.GetHbitmap(Color.FromArgb(0, 0, 0));
zero = Win32.SelectObject(ptr2, hObject);
Win32.Size size2 = new Win32.Size(bitmap.Width, bitmap.Height);
Win32.Size psize = size2;
Win32.Point point3 = new Win32.Point(0, 0);
Win32.Point pprSrc = point3;
point3 = new Win32.Point(0, 0);
Win32.Point pptDst = point3;
Win32.BLENDFUNCTION pblend = new Win32.BLENDFUNCTION();
pblend.BlendOp = 0;
pblend.BlendFlags = 0;
pblend.SourceConstantAlpha = 0xff;
pblend.AlphaFormat = 1;
Win32.UpdateLayeredWindow(this.Handle, hDC, ref pptDst, ref psize, ptr2, ref pprSrc, 0, ref pblend, 2);
Win32.ReleaseDC(IntPtr.Zero, hDC);
if (hObject != IntPtr.Zero)
{
Win32.SelectObject(ptr2, zero);
Win32.DeleteObject(hObject);
}
Win32.DeleteDC(ptr2);
Bitmap bitmap = (Bitmap)img;
IntPtr hObject = IntPtr.Zero;
IntPtr zero = IntPtr.Zero;
//获取设备上下文
IntPtr hDC = Win32.GetDC(IntPtr.Zero);
//创建一个与指定的hDC相容的内存设备上下文
IntPtr ptr2 = Win32.CreateCompatibleDC(hDC);
hObject = bitmap.GetHbitmap(Color.FromArgb(0, 0, 0));
//选定一个对象到设备上下文
zero = Win32.SelectObject(ptr2, hObject);
Win32.Size size2 = new Win32.Size(bitmap.Width, bitmap.Height);
Win32.Size psize = size2;
Win32.Point point3 = new Win32.Point(0, 0);
Win32.Point pprSrc = point3;
point3 = new Win32.Point(0, 0);
Win32.Point pptDst = point3;
Win32.BLENDFUNCTION pblend = new Win32.BLENDFUNCTION();
pblend.BlendOp = 0;
pblend.BlendFlags = 0;
pblend.SourceConstantAlpha = 0xff;
pblend.AlphaFormat = 1;
//更新位置,大小,形状,内容和一个半透明的窗体图层
Win32.UpdateLayeredWindow(this.Handle, hDC, ref pptDst, ref psize, ptr2, ref pprSrc, 0, ref pblend, 2);
//释放设备上下文
Win32.ReleaseDC(IntPtr.Zero, hDC);
if (hObject != IntPtr.Zero)
{
Win32.SelectObject(ptr2, zero);
//Deletes the attached Windows GDI object from memory by freeing all system storage associated with the Windows GDI object.
//从内存中删除这个附加的Windows GDI对象,通过释放所有系统存储器关联的Windows GDI对象
Win32.DeleteObject(hObject);
}
Win32.DeleteDC(ptr2);