Convert bitmap to byte array for upload via webservice

G

Guest

I'd like to send a bitmap image to my webservice and the prevailing logic for
desktop apps seems to be to prepare a byte array like this:

Image img = new Bitmap(@"C:\photo.jpg");
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);
byte[] imgbytes = ms.GetBuffer();

webservice.PutPhoto(imgbytes);

Unfortunately on Compact Framework an Image doesn't seem to have a Save
method. Is there a simple way to turn a bitmap into a byte array with other
classes, or do I just have to read in the bytes from disk myself?
 
A

Alex Feinman [MVP]

If your bitmap is already on the disk, why would you want to decompress it
and then compress again???
What';s wrong with
FileStream st = File.Open(@"c:\photo.jpg") ?
 
G

Guest

Doh! Then just get st.GetBuffer to get the byte array to send! My bad, I
often get muddled with all the various stream-oriented classes esp. when
looking at somebody else's example. Thank you!

Alex Feinman said:
If your bitmap is already on the disk, why would you want to decompress it
and then compress again???
What';s wrong with
FileStream st = File.Open(@"c:\photo.jpg") ?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim Johnson said:
I'd like to send a bitmap image to my webservice and the prevailing logic
for
desktop apps seems to be to prepare a byte array like this:

Image img = new Bitmap(@"C:\photo.jpg");
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);
byte[] imgbytes = ms.GetBuffer();

webservice.PutPhoto(imgbytes);

Unfortunately on Compact Framework an Image doesn't seem to have a Save
method. Is there a simple way to turn a bitmap into a byte array with
other
classes, or do I just have to read in the bytes from disk myself?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top