2017년 9월 14일 목요일

[C#] Fast array to bitmap

public Bitmap CopyDataToBitmap( byte [ ] data , int w, int h)
{
//Here create the Bitmap to the know height, width and format
Bitmap bmp = new Bitmap( w, h, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);

//Create a BitmapData and Lock all pixels to be written
BitmapData bmpData = bmp.LockBits(
  new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
  ImageLockMode.WriteOnly, bmp.PixelFormat);

//Copy the data from the byte array into BitmapData.Scan0
Marshal.Copy( data , 0 , bmpData.Scan0 , data.Length );


//Unlock the pixels
bmp.UnlockBits( bmpData );


//Return the bitmap
return bmp;
}

댓글 없음:

댓글 쓰기