
Glu.ScaleImage to OpenTK 0.9.9.3
Posted Tuesday, 3 November, 2009 - 14:04 by Mr_Dark inI have a specific function which will put the data from a bitmap in a byte[]. I used to do this with glu.ScaleImage but now I'm upgrading to OpenTK 0.9.9.3 and it's not possible anymore.
I need to have this byte[] array to I can make a specific color transparent.
// above: load bitmap from file System.Drawing.Imaging.BitmapData data; data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); byte[] bgrBuffer = new byte[bufferSizeInPixels * 3]; unsafe { fixed (byte* pBgrBuffer = bgrBuffer) { glu.ScaleImage((OpenTK.Graphics.OpenGL.PixelFormat)32992, w, h, PixelType.UnsignedByte, data.Scan0, w, h, PixelType.UnsignedByte, (IntPtr)pBgrBuffer); } } // below: loop byte array to make specific color transparent
Does anyone have an idea to fix this? I used this method in C++ and I don't know if there's a better way to do this in C#.


Comments
Re: Glu.ScaleImage to OpenTK 0.9.9.3
You can scale the System.Drawing.Bitmap directly:
Here, bitmap is the original image, scaledBitmap is the scaled image and w/h is the scaled width and height. Call this method and retrieve the BitmapData of the scaled bitmap afterwards - and don't forget to Dispose() the original bitmap if you don't need it anymore!
Re: Glu.ScaleImage to OpenTK 0.9.9.3
I was not scaling the image but putting all it's data in a byte[] so I can read that (it's in a function to create a texture).
Think I've found the solution to my problem using System.Runtime.InteropServices.Marchal