Rendering Image bits
-
What is the fastest way to render raw image bits to a Bitmap Object? I am not allowed to use unsafe code.
You mean basically what you'd pass to
CreateDIBSection
in Windows GDI? Well, you must know a few things about the bitmap data, like the width and height, or even just the stride (how many bytes in a line). You also need to know the pixel format, such as whether the data represents a 32-bit bitmap, 24-bit, etc. Fortunately, with this information GDI+ (andSystem.Graphics
) makes this easy. Use theBitmap(int, int, int, PixelFormat, IntPtr)
constructor, which takes the width, height, stride, pixel format, and a pointer to the raw data, respectively. Read more about that constructor in the .NET Framework SDK for more information.Microsoft MVP, Visual C# My Articles