Gdiplus的Graphics在DrawImage的时候,怎么指定透明度?

会录 2014-01-18 10:18:08
注意:我不是在做窗口半透明的效果。

我只是想把几幅不透明的Gdiplus::Bitmap做叠加,其中有些在叠加的时候,想给予一定的透明度。

具体叠加代码如下:




Gdiplus::Bitmap bitmap(500, 500, PixelFormat32bppARGB);
Gdiplus::Graphics graphics(&bitmap);


graphics.DrawImage(&bitmap1, 0, 0);
graphics.DrawImage(&bitmap2, 0, 0);
graphics.DrawImage(&bitmap3, 0, 0);


...全文
707 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
会录 2014-01-18
  • 打赏
  • 举报
回复
那个矩阵变换的原理,你理解么?能不能解释下?
引用 3 楼 xiaoc1026 的回复:
引用 2 楼 u013486147 的回复:
难道要自己修改图片矩阵数据中的Alpha值? 有其他方法吗? [quote=引用 1 楼 xiaoc1026 的回复:] graphics.DrawImage 没有这种功能
不好意思,好像 Status DrawImage( Image *image, const Rect &destRect, INT srcx, INT srcy, INT srcwidth, INT srcheight, Unit srcUnit, ImageAttributes *imageAttributes, DrawImageAbort callback, VOID *callbackData ); 这个函数可以实现

/// 设置图片的透明度  
       /// </summary>  
       /// <param name="image">原图</param>  
       /// <param name="alpha">透明度0-255</param>  
       /// <returns></returns>  
       private Bitmap SetPictureAlpha(Image image,int alpha)  
       {  
           //颜色矩阵  
           float[][] matrixItems =  
           {  
               new float[]{1,0,0,0,0},  
               new float[]{0,1,0,0,0},  
               new float[]{0,0,1,0,0},  
               new float[]{0,0,0,alpha/255f,0},  
               new float[]{0,0,0,0,1}  
           };  
           ColorMatrix colorMatrix = new ColorMatrix(matrixItems);  
           ImageAttributes imageAtt = new ImageAttributes();  
           imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);  
           Bitmap bmp = new Bitmap(image.Width, image.Height);  
           Graphics g = Graphics.FromImage(bmp);  
           g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),  
                   0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAtt);  
           g.Dispose();  
  
           return bmp;  
       }  
[/quote]
见习学术士 2014-01-18
  • 打赏
  • 举报
回复
引用 2 楼 u013486147 的回复:
难道要自己修改图片矩阵数据中的Alpha值? 有其他方法吗?
引用 1 楼 xiaoc1026 的回复:
graphics.DrawImage 没有这种功能
不好意思,好像 Status DrawImage( Image *image, const Rect &destRect, INT srcx, INT srcy, INT srcwidth, INT srcheight, Unit srcUnit, ImageAttributes *imageAttributes, DrawImageAbort callback, VOID *callbackData ); 这个函数可以实现

/// 设置图片的透明度  
       /// </summary>  
       /// <param name="image">原图</param>  
       /// <param name="alpha">透明度0-255</param>  
       /// <returns></returns>  
       private Bitmap SetPictureAlpha(Image image,int alpha)  
       {  
           //颜色矩阵  
           float[][] matrixItems =  
           {  
               new float[]{1,0,0,0,0},  
               new float[]{0,1,0,0,0},  
               new float[]{0,0,1,0,0},  
               new float[]{0,0,0,alpha/255f,0},  
               new float[]{0,0,0,0,1}  
           };  
           ColorMatrix colorMatrix = new ColorMatrix(matrixItems);  
           ImageAttributes imageAtt = new ImageAttributes();  
           imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);  
           Bitmap bmp = new Bitmap(image.Width, image.Height);  
           Graphics g = Graphics.FromImage(bmp);  
           g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),  
                   0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAtt);  
           g.Dispose();  
  
           return bmp;  
       }  
会录 2014-01-18
  • 打赏
  • 举报
回复
难道要自己修改图片矩阵数据中的Alpha值? 有其他方法吗?
引用 1 楼 xiaoc1026 的回复:
graphics.DrawImage 没有这种功能
见习学术士 2014-01-18
  • 打赏
  • 举报
回复
graphics.DrawImage 没有这种功能

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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