?
Solved

Converting Bitmap into array

Posted on 2004-09-12
2
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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