小编Jam*_*ron的帖子

为什么我在使用SetPixel时遇到异常:具有索引像素格式的图像不支持SetPixel?

在我正在做的课程的顶部:

private static Bitmap bmp2 = new Bitmap(@"C:\Temp\New folder (17)\radar001486.GIF");
Run Code Online (Sandbox Code Playgroud)

然后在我正在做的方法内:

private void test()
   {
    int current_list_length = pointtocolor.Count;
                for (int kk=0;kk<current_list_length;kk++)
                {

                    PointF pt = pointtocolor[kk];
                    e.FillEllipse(cloudColors[cloudColorIndex], pt.X * (float)currentFactor, pt.Y * (float)currentFactor, radius, radius);
                    bmp2.SetPixel((int)pt.X * (int)currentFactor, (int)pt.Y * (int)currentFactor, Color.Yellow);

                }
                bmp2.Save(@"c:\temp\yellowbmpcolor.bmp");
   }
Run Code Online (Sandbox Code Playgroud)

一旦它进入循环,就会在线上产生异常:

bmp2.SetPixel((int)pt.X * (int)currentFactor, (int)pt.Y * (int)currentFactor, Color.Yellow);
Run Code Online (Sandbox Code Playgroud)

如果我将从以下位置更改bmp2的实例:

private static Bitmap bmp2 = new Bitmap(@"C:\Temp\New folder (17)\radar001486.GIF");
Run Code Online (Sandbox Code Playgroud)

private static Bitmap bmp2 = new Bitmap(512,512);
Run Code Online (Sandbox Code Playgroud)

然后它会工作,但我想SetPixel原始radar001486.GIF上的像素,而不是一个新的空位图.

.net c# winforms

4
推荐指数
2
解决办法
6721
查看次数

标签 统计

.net ×1

c# ×1

winforms ×1