【问题标题】:Overlaying Bitmaps using ARGB and Graphics C#使用 ARGB 和图形 C# 覆盖位图
【发布时间】: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


【解决方案1】:

在“B”之前绘制位图“A”似乎是答案。如此简单,在这个小小的改变之前我尝试了很多。希望这对其他人有帮助

【讨论】:

  • 不知道为什么问答被否决。无论如何+1
猜你喜欢
  • 2023-04-08
  • 2011-11-20
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-16
  • 2019-07-02
相关资源
最近更新 更多