Solved

Converting Bitmap into array

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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