Solved

Converting Bitmap into array

Posted on 2004-09-12
2
212 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now