Dibsection in C#

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.
 
C

Chris Taylor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top