如何使用Bitbit绘制透明位图? [英] How To Draw Transparent Bitmap With Bitbit?

查看:97
本文介绍了如何使用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);
                }

推荐答案

您可能必须使用 AlphaBlend 功能。


无所谓我发现这是一个透明的bitbit。



Doesn't matter i found this,a transparent bitbit.

[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绘制透明位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆