4 Replies - 19224 Views - Last Post: 13 November 2014 - 09:38 AM Rate Topic: -----

#1 marklr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-July 13

c# - how to convert Byte[] RGB24bit to Bitmap?

Posted 22 November 2013 - 01:00 AM

I have Byte array image data,Byte[] ImageData(this is RGB 24BIT Image Data)

ImageConverter ic = new ImageConverter();
Image img = (Image)ic.ConvertFrom(byteArray); // Parameter not valid
Bitmap bitmap1 = new Bitmap(img);

Is This A Good Question/Topic? 0
  • +

Replies To: c# - how to convert Byte[] RGB24bit to Bitmap?

#2 SigurdSuhm   User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 111
  • Joined: 05-August 08

Re: c# - how to convert Byte[] RGB24bit to Bitmap?

Posted 22 November 2013 - 05:40 AM

Both the Image and Bitmap classes can be created from a data stream. Something like this should work:

MemoryStream bitmapDataStream = new MemoryStream(byteArray);
Bitmap bitmap = new Bitmap(bitmapDataStream);


Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7105
  • View blog
  • Posts: 24,124
  • Joined: 05-May 12

Re: c# - how to convert Byte[] RGB24bit to Bitmap?

Posted 22 November 2013 - 06:51 AM

Yes, but I was under the impression that those constructors that take a stream require not only the RGB data, but also the bitmap header before the RGB data. If what the OP is saying is accurate, then all he has is the RGB data (like in most beginner image processing and computer graphics classes). How will you figure out the bitmap/image dimensions if all you have is the series bytes? (e.g. When do you know on row of pixels ends and the next on starts?)
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct   User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2668
  • View blog
  • Posts: 4,786
  • Joined: 24-September 10

Re: c# - how to convert Byte[] RGB24bit to Bitmap?

Posted 22 November 2013 - 09:19 AM

Skydiver is right, you're going to need to know the dimensions.

If you have that you can just draw the bitmap pixel by pixel looping over the byteArray, reading out the RGB data, and putting it in the bitmap.

System.Drawing.Bitmap has methods for setting and getting pixels.

This post has been edited by lordofduct: 22 November 2013 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#5 Kutcher88   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-November 14

Re: c# - how to convert Byte[] RGB24bit to Bitmap?

Posted 13 November 2014 - 09:38 AM

lordofduct is right about Skydiver being right :)
However, copying the pixel data byte-by-byte can be slow if the bitmap isn't small. May I say that third party libraries may handle this more elegantly than native .NET libraries.

There are ways to create the image directly from byte array if you know its dimensions such as this:
create image from byte array pixel data
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1