覆盖两个或多个位图以在Picturebox中显示(C#)

在我的C#程序中,我有一个Picturebox,我想在其中显示video流(连续帧)。 我收到原始数据,然后我转换为Bitmap或Image。 我可以一次显示一个图像而没有问题(重现video流)。

现在我的问题是我想合并两个或更多具有相同大小和alpha值(ARGB)的位图(如图层)并在图片框上显示它

我在SO上阅读了很多网站和post,但很多人使用的是Graphics类,我只是无法在我的应用程序上绘制它(很可能是因为我是C#的新手!并且已经安装了我的程序,所以我不想改变结构)。

我需要(知道):

  1. 如何使用alpha值覆盖两个或多个位图;
  2. 请不要像素操纵,不能承受性能成本。

非常感谢你提前!

注意:我认为这个问题不应该被标记(或关闭)为重复,因为我在SO中找到的所有内容都是通过像素操作或通过Graphics类完成的。 (但我可能错了!)

编辑:可能的解决方法(不是问题的解决方案
在PictureBox问题中 ,第4个答案(来自用户来自)告诉我有2个picturebox,一个在另一个之上。 我必须做的唯一(额外)事情是使它与这种方法一起工作:

private void Form1_Load(object sender, EventArgs e) { pictureBox2.Parent = pictureBox1; } 

哪个pictureBox2将是顶部的那个。

我不会认为这是这个问题的答案,因为我认为这是一种解决方法(特别是因为有超过10个图片盒似乎不太理想!哈哈)。 这就是为什么我会打开这个问题等待我的问题的真正答案。

编辑:已解决! 检查我的答案。

这是我的问题的真正答案。
1)使用List存储要混合的所有图像;
2)创建一个新的位图来保存最终图像;
3)使用using语句在最终图像的graphics上绘制每个图像。

代码:

 List images = new List(); Bitmap finalImage = new Bitmap(640, 480); ... //For each layer, I transform the data into a Bitmap (doesn't matter what kind of //data, in this question) and add it to the images list for (int i = 0; i < nLayers; ++i) { Bitmap bitmap = new Bitmap(layerBitmapData[i])); images.Add(bitmap); } using (Graphics g = Graphics.FromImage(finalImage)) { //set background color g.Clear(Color.Black); //go through each image and draw it on the final image (Notice the offset; since I want to overlay the images i won't have any offset between the images in the finalImage) int offset = 0; foreach (Bitmap image in images) { g.DrawImage(image, new Rectangle(offset, 0, image.Width, image.Height)); } } //Draw the final image in the pictureBox this.layersBox.Image = finalImage; //In my case I clear the List because i run this in a cycle and the number of layers is not fixed images.Clear(); 

积分转到这个tech.pro网页上的Brandon Cannaday