作者BWF (大野狼)
看板C_Sharp
标题[问题]sharpGL撷取画面,在GDI+中发生泛型错误
时间Tue Feb 26 13:00:58 2013
我的程式是要利用sharpGL绘图後,撷取目前的图片,并储存成BMP档。
在以下事件之前,有个副程式会负责绘图(sharpGL),然後这个事件要负责撷取图片。
在Image.Save("C:\\222.bmp", System.Drawing.Imaging.ImageFormat.Bmp);,这一行会
发生"在 GDI+ 中发生泛型错误。",有爬过文了,但还是不太清楚要怎麽解决这个问题。
private void button1_Click(object sender, EventArgs e)
{
OpenGL gl = openGLControl.OpenGL;
int x = 0;
int y = 0;
int width = openGLControl.Size.Width;
int height = openGLControl.Size.Height;
byte[] pixelData = new byte[width * height * 3];
gl.PixelStore(OpenGL.GL_PACK_ALIGNMENT, 1);
gl.ReadPixels(x, y, width, height, OpenGL.GL_RGB,
OpenGL.GL_UNSIGNED_BYTE, pixelData);
Bitmap Image = new Bitmap(height, width);
for (int h = height - 1; h >= 0; h--)
{
for (int w = 0; w < width; w++)
{
Image.SetPixel(h, w, Color.FromArgb(pixelData[w],
pixelData[w + 1], pixelData[w + 2]));
}
}
Image.Save("C:\\222.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.134.32.71
※ 编辑: BWF 来自: 140.134.32.71 (02/26 13:03)