我想從 中的圖片中洗掉灰度pictureBox1,如下面的第一張照片所示。第二張照片顯示了可用于執行此操作的公式。我寫了一個近似的代碼,但是編譯器拋出一個錯誤,變數 red1、green1 和 blue1 由于型別不兼容而無法寫入 Color newPixel。請幫我修復我的代碼。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "В?дкрити зображення";
dlg.Filter = "jpg files (*.jpg)|*.jpg|All filles (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(dlg.OpenFile());
pictureBox1.Height = pictureBox1.Image.Height;
pictureBox1.Width = pictureBox1.Image.Width;
}
dlg.Dispose();
label1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap input = new Bitmap(pictureBox1.Image);
Bitmap output = new Bitmap(input.Width, input.Height);
int[] red = new int[256];
int[] green = new int[256];
int[] blue = new int[256];
for (int x = 0; x < input.Width; x )
{
for (int y = 0; y < input.Height; y )
{
Color pixel = ((Bitmap)pictureBox1.Image).GetPixel(x, y);
red[pixel.R] ;
green[pixel.G] ;
blue[pixel.B] ;
double Ri = red.Average();
double Gi = green.Average();
double Bi = blue.Average();
double Avg = (Ri Bi Gi)/3;
double red1 = red (Avg/Ri);
double green1 = green(Avg / Gi);
double blue1 = blue(Avg / Bi);
Color newPixel = ((Color)red1| (Color)green1 | (Color)blue1);
output.SetPixel(x, y, Color.((int)newPixel));
}
}
pictureBox2.Image = output;
}
}
}


uj5u.com熱心網友回復:
您應該使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/516770.html
標籤:C#表格窗体设计器
上一篇:如何在winform中使用OpenCVSharp將網路攝像頭視頻流顯示到Picturebox中?
下一篇:為什么MouseEventArgse不會在For()回圈中與Mousebuttons.(MouseButton)互動?
