调用Bitmap.SetPixel时获取ArgumentOutOfRangeException

Las*_*jgh 0 c# bitmap console-application

在某种程度上,一个不那么容易的错误已经潜入这段代码,而我不知道修复它:

static void Main(string[] args)
{
    Bitmap bm = new Bitmap(1, 1);
    bm.SetPixel(1, 1, Color.AliceBlue);
    bm.Save("C:\\Users\\Lasse\\Pictures\\Midlertidigt\\hej.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);//
    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

例外:

System.Drawing.dll中发生未处理的"System.ArgumentOutOfRangeException"类型异常

附加信息:参数必须为正且<宽度.

Jon*_*eet 5

您已经创建了一个高度和宽度为1的图像.坐标从0开始,因此唯一有效的前两个参数2 SetPixel为0:

bm.SetPixel(0, 0, Color.AliceBlue);
Run Code Online (Sandbox Code Playgroud)

唯一令人困惑的事情是如何可以很成功,通过你的描述所暗示的.