Solved

Converting Bitmap into array

Posted on 2004-09-12
2
214 Views
Last Modified: 2010-04-15
Hi,

  I have this code:

Bitmap hBitmap = new Bitmap(imageList1.Images[0]);
System.IO.Stream imgStream = new System.IO.MemoryStream();

hBitmap.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);

byte[] buffer = new byte[imgStream.Length];
imgStream.Read(buffer, 0, (int) imgStream.Length);

While the retreiving of the image from the image list is good (I can set a picturebox image to hBitmap) the buffer is always empty.  What am I missing?
0
Comment
Question by:rmyhre
2 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 total points
ID: 12039391
Bitmap hBitmap = new Bitmap(imageList1.Images[0]);
System.IO.Stream imgStream = new System.IO.MemoryStream();

hBitmap.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);

// this is the missing line:
imgStream.Position = 0;

byte[] buffer = new byte[imgStream.Length];
imgStream.Read(buffer, 0, (int) imgStream.Length);
0
 

Author Comment

by:rmyhre
ID: 12039501
Wow... that would be embarrasing any of the hundreds of lines of code that I researched had actually shown it and I just missed it.  But that isn't the case so I can still walk (moderately) tall.  :)

Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question