471,596 Members | 879 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

How do I convert a Bitmap to a byte[]

I have a Bitmap (bm) that I am able to save using, for example,
bm.Save("file.jpg", System.Drawing.Imaging.ImageFormat.Jpeg). However, I
would like to convert this to a byte array (byte[]). What is the best way to
do this?
Jun 27 '08 #1
2 2606
Bill Fuller wrote:
I have a Bitmap (bm) that I am able to save using, for example,
bm.Save("file.jpg", System.Drawing.Imaging.ImageFormat.Jpeg). However, I
would like to convert this to a byte array (byte[]). What is the best way to
do this?
It has an overload that takes a Stream as first argument. Pass a
MemoryStream object.

Arne
Jun 27 '08 #2
On Fri, 06 Jun 2008 20:00:48 -0700, Arne Vajhøj <ar**@vajhoej.dkwrote:
Bill Fuller wrote:
>I have a Bitmap (bm) that I am able to save using, for example,
bm.Save("file.jpg", System.Drawing.Imaging.ImageFormat.Jpeg). However,
I would like to convert this to a byte array (byte[]). What is the best
way to do this?

It has an overload that takes a Stream as first argument. Pass a
MemoryStream object.
And then after you've saved the Bitmap to that MemoryStream, use
MemoryStream.ToArray() to convert to a byte[].

Pete
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fritz Switzer | last post: by
2 posts views Thread by Eka Gautama | last post: by
2 posts views Thread by Clas Hortien | last post: by
2 posts views Thread by cosminb | last post: by
3 posts views Thread by ShihChengYu | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.