覆盖两个或多个位图以在Picturebox中显示(C#)
在我的C#程序中,我有一个Picturebox,我想在其中显示视频流(连续帧).我收到原始数据,然后我转换为Bitmap或
Image.我可以一次显示一个图像而没有问题(重现视频流).
现在我的问题是我想合并2个或更多位图(如图层)具有相同的大小和alpha值(ARGB)并在图片框上显示它. 我在SO上阅读了很多网站和帖子,但很多都使用Graphics类,我只是无法在我的应用程序上绘制它(很可能是因为我是C#的新手!并且已经有我的程序设置,所以我不想改变结构). 我需要(知道): >如何使用alpha值覆盖两个或多个位图; 非常感谢你提前! 注意:我认为这个问题不应该被标记(或关闭)为重复,因为我在SO中找到的所有内容都是通过像素操作或通过Graphics类完成的. (但我可能错了!) 编辑:可能的解决方法(不是问题的解决方案) private void Form1_Load(object sender,EventArgs e) { pictureBox2.Parent = pictureBox1; } 哪个pictureBox2将是顶部的那个. 我不会认为这是这个问题的答案,因为我认为这是一种解决方法(特别是因为有超过10个图片盒似乎不太理想!哈哈).这就是为什么我会打开这个问题等待我的问题的真正答案. 编辑:已解决!检查我的答案. 解决方法
这是我的问题的真正答案.
1)使用List< Bitmap>存储您想要混合的所有图像; 2)创建一个新的位图来保存最终图像; 3)使用using语句在最终图像的图形上绘制每个图像. 代码: List<Bitmap> images = new List<Bitmap>(); 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,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(); 积分将于this tech.pro webpage年送到Brandon Cannaday. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Oracle 11g 默认用户名和密码
- c – 整数溢出未定义在内联x86程序集中?
- c – 从libevent移植到boost :: asio:什么是ASIO中libeven
- swift 字符串
- SQLite插入性能
- Sqlite3的简单用法,得到行数和列值【附源码和文件】
- c# – 当多线程时,循环索引超出范围ArgumentOutOfRangeExce
- 使用 EntitysCodeGenerate 生成 PostgreSQL 的代码
- debian8下配置postgresql9.5.2、pgpool3.5.2、heartbeat3.0
- c# – 如何访问Ninject.Kernel而不使用Service Locator模式