我正在嘗試用 C# 進行一些影像處理,我有一個影像pictureBox1和另一個pictureBox2。我將沒有灰度的原始影像加載到第一個PictureBox中,然后放置一個按鈕事件處理程式將該幀內影像中的Bitmap處理為灰度,然后將處理結果顯示到第二個PictureBox中。當我單擊按鈕時,型別為ArgumentOutOfRangeException: Parameter must be positive and < Width. (Parameter 'x'). 按鈕處理程式內的代碼如下
//get the graysale representation of this image and assign
Bitmap mymap= new Bitmap(image_path);
//Rectangle myrect= new Rectangle(0,0,mymap.Width,mymap.Height);
Bitmap newmap=new Bitmap(mymap.Height,mymap.Width,mymap.PixelFormat);
Color p;
for(int y = 0; y < mymap.Height; y )
{
for(int x = 0; x < mymap.Width; x )
{
p=mymap.GetPixel(x,y);
//get the opacity of this color
int a=p.A;
//get the red component of this pixel
int r = p.R;
//get the green component of this pixel
int g = p.G;
//get the blue component of this pixel
int b = p.B;
//get the average of these colors which is the gray scale
int av=(b g r)/ 3;
//assign to the new Bitmap
newmap.SetPixel(x,y,Color.FromArgb(a,av,av,av));
}
}
//assign to pictureBox 2
pictureBox2.Image=newmap;
我究竟做錯了什么?
uj5u.com熱心網友回復:
改變這個:
Bitmap(mymap.Height,mymap.Width,mymap.PixelFormat);
對此:
Bitmap(mymap.Width,mymap.Height,mymap.PixelFormat);
位圖建構式需要引數: Width, Height, PixelFormat
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367537.html
上一篇:如何使用標準的unix命令為HTML檔案中的id附加后綴?
下一篇:任何想法如何解決快速影片背景圖片
