【发布时间】:2016-08-11 00:57:34
【问题描述】:
我正在尝试叠加两个位图
我有 2 个 ARGB (Format32bppArgb) 位图。位图“A”的某些像素区域的 apha 通道值为 0(透明),而其他像素区域的值范围为 ~200 - 255。位图“B”像素的 alpha 通道的值都为 255。我正在绘制它们中的每一个像这样的图形......
Bitmap OverlayBitmaps(Bitmap underlying, Bitmap overlaying)
{
Bitmap finalImage = new Bitmap(underlying.Width, underlying.Height,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(finalImage))//get the underlying graphics object from the image.
{
graphics.DrawImage(underlying, new Rectangle(0,0, underlying.Width, underlying.Height));
graphics.DrawImage(overlaying, new Rectangle(0, 0, overlaying.Width, overlaying.Height));
finalImage.Save("C:\\test.bmp");
return finalImage;
}
}
“A”和“B”的格式相同,高度相同,宽度相同,但是当我保存图像时,看起来好像只绘制了“B”。
这是因为“B”alpha通道值占主导地位吗?
我认为先绘制“B”,然后绘制“A”,“A”的 alpha 通道值约为 200-250 的像素将位于“B”之上
我一定是遗漏了什么……有什么建议吗?
【问题讨论】:
-
将文件保存为 PNG 并查看它的外观 - 指定图像格式
-
已解决:在 B 之前绘制位图 A。抱歉这个愚蠢的问题 :)
标签: c# graphics bitmap alpha-transparency