【发布时间】:2014-09-23 07:47:45
【问题描述】:
在我正在做的一门课的顶部:
private static Bitmap bmp2 = new Bitmap(@"C:\Temp\New folder (17)\radar001486.GIF");
然后在我正在做的一个方法中:
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");
}
一旦进入循环,它就会产生异常:
bmp2.SetPixel((int)pt.X * (int)currentFactor, (int)pt.Y * (int)currentFactor, Color.Yellow);
如果我将 bmp2 的实例更改为:
private static Bitmap bmp2 = new Bitmap(@"C:\Temp\New folder (17)\radar001486.GIF");
到
private static Bitmap bmp2 = new Bitmap(512,512);
然后它会工作,但我想 SetPixel 原始雷达001486.GIF 上的像素,而不是新的空位图。
【问题讨论】:
-
SetPixel面临的问题是当前调色板中可能不存在您指定的颜色。
-
你可以查看这个帖子,它是相同的主题[链接][1] [1]:stackoverflow.com/questions/2840138/…