Windows Develop Bookmark and Share   
 index > Windows Forms General > How to display a bitmap created from a raw pixel data array ?
 

How to display a bitmap created from a raw pixel data array ?

Folks,

I have a raw pixel data array that is 16bppGrayScale. The data is in a 1-d byte array, 2 bytes per pixel, padded to end

a row on a 4 byte bounday (held in image.Data below)

Here is my code that doesn't draw? What is wrong? ?????

same code works if I read the bmp in from disk and instead of assigning dataArray = image.Data, do byte[] dataArray = new byte[height*width*3];

Bitmap bmp = new Bitmap(image.ImageWidth, image.ImageLength, PixelFormat.Format16bppGrayScale);


Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format16bppGrayScale);


IntPtr ptr = bmpData.Scan0;

int limit = image.Data.Length;

byte[] dataArray = image.Data;


Marshal.Copy(ptr, dataArray, 0, dataArray.Length);


bmp.UnlockBits(bmpData);


e.Graphics.DrawImage(bmp, 0, 0);

hoopinCowgirl  Friday, May 09, 2008 5:25 AM

It is doubtful that you have a 16 bit graphics card, so convert the data to 8 bits before creating the bitmap.

JohnWein  Friday, May 09, 2008 5:39 AM

It is doubtful that you have a 16 bit graphics card, so convert the data to 8 bits before creating the bitmap.

JohnWein  Friday, May 09, 2008 5:39 AM

You can use google to search for other answers

Custom Search

More Threads

• Form Caption Issue
• Passing Object from form to form.
• i need some help !!
• Select/De select all in checkedlistbox error
• Print Graph in Window Application.
• Delete selected listview item
• How to convert a .NET Application(WinForm) to Active X Control
• How do I add table functionality to a richTextBox control?
• Scroll Bar is stuck on the left...
• Finding Control's Default Built-In ContextMenu