Home of the Open Toolkit library

I'm trying to save the rendering to disk and found the OpenTK tutorial that supposedly tells how to do it (http://www.opentk.com/doc/graphics/save-opengl-rendering-to-disk). I changed it a little bit so it could work with glControl1 of Windows.Forms but it throws me an Argument Exception that according to the MSDN website (http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx) it's because there's something wrong with "System.Drawing.Imaging.PixelFormat.Format24bppRgb". It tells that: "The PixelFormat is not a specific bits-per-pixel value. -or- The incorrect PixelFormat is passed in for a bitmap."

Comment viewing options

System.Drawing is a little strange in its handling of pixel formats. Try using OpenTK.Graphics.OpenGL.PixelFormat.Bgra and System.Drawing.Imaging.PixelFormat.Format32bppRgba - these formats have always worked for me.

thanks for the reply :) but it still doesn't work for me. I changed it to OpenTK.Graphics.OpenGL.PixelFormat.Bgra and to System.Drawing.Imaging.PixelFormat.Format32bppArgb and still nothing. Actually I couldn't find "Format32bppRgba" as you said. VS told me that there was no definition for it in System.Drawing.Imaging.PixelFormat, that's why I used "Format32bppArgb". I thought it would be the most similar since both "A" stand for "alpha channel"...I guess :S

The actual line that throws the exception isBitmapData data = bmp.LockBits(r, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

It says the t the Format32bppArgb is an invalid parameter. And yes, I do have write access to the root of C:\, but actually C:\\plot.bmp was not my actual path. I put it that way just to make the code clearer..I thought :P .

The problem is your rectangle, you need to switch the glControl1.Location to just a new Point(). Currently you're specifying an area partially outside the bitmap and LockBits doesn't clip the rectangle (for obvious reasons).

The problem now is that the image saved is obviously not the size of glControl1 and it doesn' show correctly the actual render. I attach hereby the 2 images: the saved render and a printScreen of how it should actually look.