帮助减去两个图像 [英] Help in subtraction of two images
本文介绍了帮助减去两个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帮助!
将两个图像按像素相减会给我一个错误:
Help!
The subtraction of two images by pixel gives me an error:
int h, w;
h = pictureEdit1.Image.Height;
w = pictureEdit1.Image.Width;
Bitmap b = new Bitmap(h,w );
Bitmap p1 = (Bitmap )pictureEdit1.Image;
Bitmap p2 = (Bitmap)pictureEdit2.Image;
try
{
for (int x = 0; x <= pictureEdit1.Image.Height; x++)
{
for (int i = 0; i <= pictureEdit1.Image.Width; i++)
{
if (p1.GetPixel(i, x) != p2.GetPixel(i,x))
{
pictureEdit1.Image.Height.ToString());
b.SetPixel(x, i, p2.GetPixel(x, i));
}
//else
//{
// b.SetPixel(x, i, Color.Red);
//}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
pictureEdit3.Image = b;
异常错误
参数必须为正且<高度.
参数名称:y
Exception Error
Parameter must be positive and < Height.
Parameter name: y
推荐答案
似乎您在那儿交换了宽度和高度.您以x轴为picture1的高度,以y轴为picture1的宽度.应该是另一种方式.那是那里最明显的事情.您的代码中可能存在或没有其他问题-很难说.
~~~~~~~~
好的,即使在最上面,您也正在创建一个新的位图,将其宽度-高度互换,所以也许您打算那样做?代码相当混乱.
It seems you swapped up width and height there. You take picture1''s height for the x axis and picture1''s width for the y axis. It should be the other way. That was the most obvious thing there. There may or may not be other issues in your code - hard to say.
~~~~~~~~
Okay, even on top, you are creating a new Bitmap with the width-height swapped, so perhaps you intended it that way? The code is rather confusing.
我认为是您的循环使您绊倒.
看一下外部循环,您已经使用过<=
和.Height +1
看一下内部循环,您已经使用过<=
和.Width
它们应该被同等对待.
我想您会在两个循环中都使用<
和.Height
或.Width
.
I think it is your loops that are tripping you up.
Look at the outer loop, you have used<=
and.Height +1
Look at the inner loop, you have used<=
and.Width
They should both be treated the same.
I would think you would want to use<
and.Height
or.Width
for both the loops.
伙计,您那里有些奇怪的事情.
首先,按照惯例,使用变量"x"进行遍历,使用"y"进行遍历.不是"i".
出现此错误似乎是因为您超出了高度范围,在这里循环:
Man, you''ve got some strange stuff going on there.
Firstly, by convention use a variable ''x'' to go across and ''y'' to go up. Not ''i''.
The error looks like it comes about because you''re going out of range on the height, looping here:
for (int x = 0; x <= pictureEdit1.Image.Height+1; x++)
当然应该是:
surely should be:
for (int y = 0; y < pictureEdit1.Image.Height; y++)
仍然不确定要做什么.
另外,位图"b"-宽度总是在高度之前-您是在侧面对其进行构造...
Still not sure what you want to do mind.
Also, the bitmap ''b'' - width always comes before height - you''re constucting it on its side...
这篇关于帮助减去两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文