社区
C++ 语言
帖子详情
transparentBlt可以实现多种颜色透明吗?
cavehubiao
2013-09-21 10:51:43
比如这样的 我想让背景蓝色和人物周围不规则的绿色透明,该怎么贴
transparentBlt好像只能让crTransparent参数所指向的颜色透明 ,要是多种怎么办
...全文
140
4
打赏
收藏
transparentBlt可以实现多种颜色透明吗?
比如这样的 我想让背景蓝色和人物周围不规则的绿色透明,该怎么贴 transparentBlt好像只能让crTransparent参数所指向的颜色透明 ,要是多种怎么办
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
赵4老师
2013-09-22
打赏
举报
回复
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/usingGDIPlus/alphablendinglinesandfills/usingacolormatrixtosetalphavaluesinimages.htm
Using a Color Matrix to Set Alpha Values in Images -------------------------------------------------------------------------------- The Bitmap class (which inherits from the Image class) and the ImageAttributes class provide functionality for getting and setting pixel values. You can use the ImageAttributes class to modify the alpha values for an entire image, or you can call the Bitmap::SetPixel method of the Bitmap class to modify individual pixel values. For more information on setting individual pixel values, see Setting the Alpha Values of Individual Pixels. The following example draws a wide black line and then displays an opaque image that covers part of that line. Bitmap bitmap(L"Texture1.jpg"); Pen pen(Color(255, 0, 0, 0), 25); // First draw a wide black line. graphics.DrawLine(&pen, Point(10, 35), Point(200, 35)); // Now draw an image that covers part of the black line. graphics.DrawImage(&bitmap, Rect(30, 0, bitmap.GetWidth(), bitmap.GetHeight())); The following illustration shows the resulting image, which is drawn at (30, 0). Note that the wide black line doesn't show through the image. The ImageAttributes class has many properties that you can use to modify images during rendering. In the following example, an ImageAttributes object is used to set all the alpha values to 80 percent of what they were. This is done by initializing a color matrix and setting the alpha scaling value in the matrix to 0.8. The address of the color matrix is passed to the ImageAttributes::SetColorMatrix method of the ImageAttributes object, and the address of the ImageAttributes object is passed to the DrawImage method of a Graphics object. Show Example // 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); During rendering, the alpha values in the bitmap are converted to 80 percent of what they were. This results in an image that is blended with the background. As the following illustration shows, the bitmap image looks transparent; you can see the solid black line through it. Where the image is over the white portion of the background, the image has been blended with the color white. Where the image crosses the black line, the image is blended with the color black. -------------------------------------------------------------------------------- © 2005 Microsoft Corporation. All rights reserved.
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/usingGDIPlus/alphablendinglinesandfills/settingthealphavaluesofindividualpixels.htm
Setting the Alpha Values of Individual Pixels -------------------------------------------------------------------------------- The topic Using a Color Matrix to Set Alpha Values in Images shows a nondestructive method for changing the alpha values of an image. The example in that topic renders an image semitransparently, but the pixel data in the bitmap is not changed. The alpha values are altered only during rendering. The following example shows how to change the alpha values of individual pixels. The code in the example actually changes the alpha information in a Bitmap object. The approach is much slower than using a color matrix and an ImageAttributes object but gives you control over the individual pixels in the bitmap. Show Example INT iWidth = bitmap.GetWidth(); INT iHeight = bitmap.GetHeight(); Color color, colorTemp; for(INT iRow = 0; iRow < iHeight; iRow++) { for(INT iColumn = 0; iColumn < iWidth; iColumn++) { bitmap.GetPixel(iColumn, iRow, &color); colorTemp.SetValue(color.MakeARGB( (BYTE)(255 * iColumn / iWidth), color.GetRed(), color.GetGreen(), color.GetBlue())); bitmap.SetPixel(iColumn, iRow, colorTemp); } } // First draw a wide black line. Pen pen(Color(255, 0, 0, 0), 25); graphics.DrawLine(&pen, 10, 35, 200, 35); // Now draw the modified bitmap. graphics.DrawImage(&bitmap, 30, 0, iWidth, iHeight); The following illustration shows the resulting image. The preceding code example uses nested loops to change the alpha value of each pixel in the bitmap. For each pixel, Bitmap::GetPixel gets the existing color, Color::SetValue creates a temporary color that contains the new alpha value, and then Bitmap::SetPixel sets the new color. The alpha value is set based on the column of the bitmap. In the first column, alpha is set to 0. In the last column, alpha is set to 255. So the resulting image goes from fully transparent (on the left edge) to fully opaque (on the right edge). Bitmap::GetPixel and Bitmap::SetPixel give you control of the individual pixel values. However, using Bitmap::GetPixel and Bitmap::SetPixel is not nearly as fast as using the ImageAttributes class and the ColorMatrix structure. -------------------------------------------------------------------------------- © 2005 Microsoft Corporation. All rights reserved.
大尾巴猫
2013-09-21
打赏
举报
回复
这应该是ps干的活。
unituniverse2
2013-09-21
打赏
举报
回复
用ps自己p
lm_whales
2013-09-21
打赏
举报
回复
不知可不可以 不过你可以统一一下两种颜色。
关于
Transparent
Blt
透明
显示问题
关于
Transparent
Blt
透明
显示问题
透明
位图的
实现
原理
透明
位图的绘制的
实现
原理
透明
色的位图的绘制方法有
多种
,最简单的方法是调用现成的函数:
Transparent
Blt
,也可以自己代码
实现
类似的功能,
实现
过程也有两种方式,一种是事先做一张掩码位图作为资源,另一种是动态...
VC——位图的
透明
显示
id=532 王俊的《
透明
位图的显示》。...包含
透明
色的位图的绘制方法有
多种
,最简单的方法是调用现成的函数:
Transparent
Blt
,也可以通过自己的代码
实现
类似
Transparent
Blt
的功能,
实现
过程也有两种形式,一种是事先做一
透明
位图的绘制
绘制"
透明
"位图是指绘制某一位图中除指定
颜色
外的其余部分,我们称这种
颜色
为"
透明
色"。通过将位图的背景色指定为"
透明
色",在绘制时,不绘制这部分背景,而仅绘制图像,这样就可以将位图中图像
透明
地绘制到窗口上。...
VC图片去背景方法
包含
透明
色的位图的绘制方法有
多种
,最简单的方法是调用现成的函数:
Transparent
Blt
,也可以通过自己的代码
实现
类似
Transparent
Blt
的功能,
实现
过程也有两种形式,一种是事先做一张掩码位图,另一种是动态生成...
C++ 语言
64,654
社区成员
250,484
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章