我想要的图像绘制到一个图片(pbImage
)并将其转换成后位,但它崩溃,因为pcImage.Image
是apperently null
,我可以看到图纸崩溃,所以我不明白是怎么回事null
之前。转换时c#崩溃,显然为空?
以下是错误:
An unhandled exception of type 'System.NullReferenceException' occurred in System.Drawing.dll Additional information: Object reference not set to an instance of an object.
bool[,] bCollision = new bool[pbImage.Width,pbImage.Height];
Color cPixelCol;
Graphics G = Graphics.FromHwnd(pbImage.Handle);
Pen SquarePen = new Pen(Color.Black, 5);
SquarePen = new Pen(Color.Red, 5);
Brush BackBrush = new SolidBrush(Color.Aqua);
G.FillRectangle(BackBrush, 50, 50, this.Width, this.Height);
G.DrawLine(SquarePen, 410, 50, 410, 400);
G.DrawEllipse(SquarePen, 50 + x, 50, 100+x, 50);
Bitmap bm = new Bitmap(pbImage.Image); <------------- this line crashes
我的猜测是'pbImage.Image'为空。无论如何,我们不是在这里调试你的代码,你有没有试过找到你在20秒内完成的原因,这就是为什么我低估了这个问题。 – gdoron
'pbImage.Image'从未在此代码中设置...因此它可能为空... – emd
尝试在创建图形前查看'pbImage.Image'并查看它是否为空 – BrunoLM