Solved

Converting Bitmap into array

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

11 Experts available now in Live!

Get 1:1 Help Now