就是我有个Bitmap数据,想设置它的透明度Alpha值,怎么设置?
解决方案 »
- 同一个单文档文件,有两个对话框在初始化中调用同一个access数据库,运行报错:unknown error ox800A0E7D
- CreateDispatch(_T("Excel.Application"))报错
- 有人能教我怎么在一副位图里画个矩形框吗?
- 谁有InstallShield for Microsoft Visual C++ 6的三个汉化文件,给我发一份,谢谢!
- activeX控件的动态创建问题 to(Microsoftadherent(王万新) )
- 工作线程有没有消息队列?有没有方法实现类似消息队列的功能?
- 高手求救!!!!有关子窗口的问题!!!!!
- window下的图形程序是不是一定要调用creatwindow这个api?
- 寻找i/DATABASE源码
- 300分请问共享软件InstallShield for Windows Installer (版本号:V2.03简版)的密码?
- 读取CPU温度 为什么读不出来 求助.....
- 这段代码已经切换到Winsta/Default桌面了,咋还是只能弹框,不能显示其他界面呢?
如果没有,应该可以在渲染时指定一个aplha值.
你还可以参考哈我才发的帖子,用directx实现的colormatrix就知道他原理了。
代码如下:// Create a Bitmap object and load it with the texture image.
Bitmap bitmap(L"Texture1.jpg");
Pen pen(Color(255, 0, 0, 0), 25);
// Initialize the color matrix.
// Notice the value 0.8 in row 4, column 4.
ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.8f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
// Create an ImageAttributes object and set its color matrix.
ImageAttributes imageAtt;
imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault,
ColorAdjustTypeBitmap);
// First draw a wide black line.
graphics.DrawLine(&pen, Point(10, 35), Point(200, 35));
// Now draw the semitransparent bitmap image.
INT iWidth = bitmap.GetWidth();
INT iHeight = bitmap.GetHeight();
graphics.DrawImage(
&bitmap,
Rect(30, 0, iWidth, iHeight), // Destination rectangle
0, // Source rectangle X
0, // Source rectangle Y
iWidth, // Source rectangle width
iHeight, // Source rectangle height
UnitPixel,
&imageAtt);
但是我用了imageAttr的SetColorKey来去除底色,再用你这个方法的话,我就去除不了底色了。
hdc = BeginPaint(hWnd, &ps);
Graphics graphics(hdc);
Bitmap bitmap(L"32.jpg");
Pen pen(Color(255, 0, 0, 0), 25);
// Initialize the color matrix.
// Notice the value 0.8 in row 4, column 4.
SolidBrush solidBrush(Color(255, 255, 0, 0));
graphics.FillRectangle(&solidBrush, 0, 0, 500, 600);
ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
// Create an ImageAttributes object and set its color matrix.
ImageAttributes imageAtt;
imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault,
ColorAdjustTypeBitmap);
imageAtt.SetColorKey(0,10,ColorAdjustTypeBitmap);
// First draw a wide black line.
//graphics.DrawLine(&pen, Point(10, 35), Point(200, 35));
// Now draw the semitransparent bitmap image.
INT iWidth = bitmap.GetWidth();
INT iHeight = bitmap.GetHeight();
graphics.DrawImage(
&bitmap,
Rect(30, 0, iWidth, iHeight), // Destination rectangle
0, // Source rectangle X
0, // Source rectangle Y
iWidth, // Source rectangle width
iHeight, // Source rectangle height
UnitPixel,
&imageAtt);
EndPaint(hWnd, &ps);
你找个背景为黑色的就可以了我设置的是
imageAtt.SetColorKey(0,10,ColorAdjustTypeBitmap);