Dibsection in C#

  • Thread starter Thread starter _E5_
  • Start date Start date
E

_E5_

I had been using Dibsection with MFC (as an alternative to DirectX).
Looks like C# has no support for this, or even for bitblt.

What is the alternative?

Are there good classes available that wrap these for C#? Seems like a
logical thing to do.
 
Hi,

You can create a Bitmap and call LockBits, this will allow you to work
directly with the bits using an unsafe block in C#, when you are done you
call UnlockBits and then use Graphics.DrawImage to draw the bitmap. To use
the code below you have to enable Unsafe code blocks for the project.

Bitmap bmp = new Bitmap( 100, 100 );
System.Drawing.Imaging.BitmapData data = bmp.LockBits( new
Rectangle( 0, 0, 100, 100 ),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppRgb );

unsafe
{
byte *b = (byte*)data.Scan0;

// Use *b to change the contents of the bitmap
}
bmp.UnlockBits( data );

// Draw the bitmap
e.Graphics.DrawImageUnscaled( bmp, 0, 0 );

Hope this helps
 
Back
Top