本文介绍了如何使用Bitbit绘制透明位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我在C#中用这个代码在控件上绘制位图,不幸的是,Drawed背景颜色是灰色但我的Bitmap是透明的。你能帮我吗?
hi everyone i used this code in C# for draw bitmap on Control,Unfortunately, the Drawed background color is gray But my Bitmap is Transparent.Can you help me please?
try
{
hdcDest = grpDest.GetHdc();
hdcSrc = grpSrc.GetHdc();
hBitmap = bmp.GetHbitmap();
hOldObject = SelectObject(hdcSrc, hBitmap);
if (hOldObject == IntPtr.Zero)
throw new Win32Exception();
if (!BitBlt(hdcDest, 0, 0, Width, Height,
hdcSrc, 0, 0,SRCCOPY))
throw new Win32Exception();
}
finally
{
if (hOldObject != IntPtr.Zero) SelectObject(hdcSrc, hOldObject);
if (hBitmap != IntPtr.Zero) DeleteObject(hBitmap);
if (hdcDest != IntPtr.Zero) ReleaseHdc(hdcDest);
if (hdcSrc != IntPtr.Zero) ReleaseHdc(hdcSrc);
}
推荐答案
[System.Runtime.InteropServices.DllImportAttribute ("msimg32.dll")]
public static extern bool TransparentBlt (IntPtr hdc, int nXOriginDest, int nYOriginDest, int nWidthDest, int hHeightDest, IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, uint crTransparent);
这篇关于如何使用Bitbit绘制透明位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!