如何同时实现图片的透明度和透明色打印?

码到成功 2009-04-08 01:40:34
现有一张图片,有一种颜色需要过滤掉,其余部分要按某种透明度打印,如何实现?
我用了下面的代码,但是无法实现过滤颜色,请大家帮忙:
void DrawPicture(HWND hwnd, HDC hDC, HBITMAP hBitmap)
{
RECT rc;
BITMAP bmTime;
HDC hTimeDC;
BOOL bRet;
COLORREF color = RGB(0,0,0);

GetWindowRect(hwnd,&rc);
GetObject( hBitmap, sizeof(bmTime),&bmTime);
hTimeDC = CreateCompatibleDC(hDC);
bRet = TransparentImage( hTimeDC,0,20,bmTime.bmWidth ,bmTime.bmHeight, hBitmap, 0, 0,bmTime.bmWidth ,bmTime.bmHeight ,color);
SelectObject(hTimeDC, hBitmap);
BLENDFUNCTION blend = { AC_SRC_OVER, 0,50, 0/*AC_SRC_ALPHA */};
bRet = AlphaBlend(hDC, 0, 20, bmTime.bmWidth, bmTime.bmHeight, hTimeDC, 0, 0, bmTime.bmWidth, bmTime.bmHeight , blend);
ReleaseDC(hwnd,hTimeDC);
}
...全文
421 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
码到成功 2009-04-27
  • 打赏
  • 举报
回复
还是实现不了啊。。
世外涛缘 2009-04-08
  • 打赏
  • 举报
回复
或者用P/Invoke调用API : AlphaBlend
示例如下:
public struct BlendFunction
{
public byte BlendOp;
public byte BlendFlags;
public byte SourceConstantAlpha;
public byte AlphaFormat;
}

public enum BlendOperation : byte
{
AC_SRC_OVER = 0x00
}

public enum BlendFlags : byte
{
Zero = 0x00
}

public enum SourceConstantAlpha : byte
{
Transparent = 0x00,
Opaque = 0xFF
}

public enum AlphaFormat : byte
{
AC_SRC_ALPHA = 0x01
}

public class PlatformAPIs
{
[DllImport("coredll.dll")]
extern public static Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32 yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32 ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction);
}
世外涛缘 2009-04-08
  • 打赏
  • 举报
回复
System.Drawing.Imaging.ImageAttributes.SetColorKey();
Graphics.DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes);
这两个方法应该可以实现。
码到成功 2009-04-08
  • 打赏
  • 举报
回复
没有一个人回答,郁闷。。。自己顶起来

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧