Author: techfox9

Pointers in C# (CSharp) .. example with bits..

Thursday, February 12th, 2009 @ 4:57 pm

// 32 bit source Bitmap
System.Drawing.Bitmap b

int bWidth, bHeight;
int idx = 0;

bWidth = b.Width;
bHeight = b.Height;

byte[,] Disp = new byte[bWidth, bHeight];

// create a new 16 bit bitmap
Bitmap b565 = new Bitmap(b.Size.Width,b.Size.Height,System.Drawing.Imaging.PixelFormat.Format16bppRgb565);

Graphics g = Graphics.FromImage(b565);
// draw the 32 bit source bitmap to the 16 bit bitmap
g.DrawImage(b, new Point(0, 0));
g.Dispose();

BitmapData bmd = b565.LockBits(new Rectangle(0, 0, 480, 272), System.Drawing.Imaging.ImageLockMode.ReadOnly, b565.PixelFormat);

byte[] Result = new byte[bWidth * bHeight * 2];

unsafe
{
   // get a pointer to the beginning of image data in the 16 bit bitmap
   byte* bitdata = (byte*)bmd.Scan0;

   for (int y = 0; y < bmd.Height*bmd.Width*2; y++)
   {
       // just copy the image data from the Bitmap to the byte array
       Result[y] = bitdata[y];
   }
}

b565.UnlockBits(bmd);
USBD480_DrawFullScreen(ref di, Result);

.Net, Microsoft


 


Comments are closed.