c# - 如何使用 C# 比较两个图像并获得透明背景图像?
问题描述
在此示例中,使用 C# 如何将白色图像与黑色图像进行比较以获得透明背景图像?
这里的问题是在这段代码中,将白色图片与黑色图片进行比较,并返回背景灰色图片。
var image = new Bitmap(this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);
var rect = new Rectangle(0, 0, this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);
Graphics graphics = Graphics.FromImage(image);
graphics.DrawImage(this.pictureBox1.Image, 0, 0);
var waterMarkImage = new Bitmap(this.pictureBox2.Image.Width, this.pbox_2resim.Image.Height);
for (int y = 0; y < waterMarkImage.Height; y++)
{
for (int x = 0; x < waterMarkImage.Width; x++)
{
var color = (this.pictureBox2.Image as Bitmap).GetPixel(x, y);
color = Color.FromArgb(50, color.R, color.G, color.B);
waterMarkImage.SetPixel(x, y, color);
}
}
graphics.DrawImage(waterMarkImage, rect);
this.pictureBox3.Image = image;
解决方案
推荐阅读
- c# - 在 C# 中的选定文本位置之前和之后插入 HTML TAG
- dependency-injection - NestJS 在守卫中注入服务
- arrays - 如何摆脱这个简单的 SwiftUI 错误?
- assembly - 我无法将我的登录密码与我的注册密码进行比较。谁能给我一个解决方案来解决它?
- python - 如何在 TENANT_MODEL 中使用多模型
- php - php artisan make:auth 未在 Laravel 8 中定义
- ajax - ajax MissingServletRequestParameterException:所需的请求参数不存在]
- android - 当我将高度设置为换行或匹配或 0dp 时,listview 项目未显示,它们仅在我使用特定数字时显示
- prolog - 积极因素清单
- python - Tensorflow(keras)模型总是给我相同的价值