[問題]sharpGL擷取畫面,在GDI+中發生泛型錯誤
我的程式是要利用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)