C#:绘制一个位图到另一个,与透明 [英] C#: Draw one Bitmap onto Another, with Transparency
本文介绍了C#:绘制一个位图到另一个,与透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个位图,命名为largeBmp和smallBmp。我想提请smallBmp到largeBmp,那么结果绘制到屏幕上。 SmallBmp的白色像素应该是透明的。下面是我使用的代码:
I have two Bitmaps, named largeBmp and smallBmp. I want to draw smallBmp onto largeBmp, then draw the result onto the screen. SmallBmp's white pixels should be transparent. Here is the code I'm using:
public Bitmap Superimpose(Bitmap largeBmp, Bitmap smallBmp) {
Graphics g = Graphics.FromImage(largeBmp);
g.CompositingMode = CompositingMode.SourceCopy;
smallBmp.MakeTransparent();
int margin = 5;
int x = largeBmp.Width - smallBmp.Width - margin;
int y = largeBmp.Height - smallBmp.Height - margin;
g.DrawImage(smallBmp, new Point(x, y));
return largeBmp;
}
的问题是,其结果卷起透明无论smallBmp是透明的!我只是想通过对largeBmp,没有什么是它背后看到的。
The problem is that the result winds up transparent wherever smallBmp was transparent! I just want to see through to largeBmp, not to what's behind it.
推荐答案
CompositingMode.SourceCopy
是这里的问题。你想 CompositingMode.SourceOver
来获取alpha混合。
CompositingMode.SourceCopy
is the problem here. You want CompositingMode.SourceOver
to get alpha blending.
这篇关于C#:绘制一个位图到另一个,与透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文