469,943 Members | 2,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

Converting image to byte array

Hi.

This story is about uploading jpg's, then resize them to fixed width or
height and storing them to an SQL table.
The only way I have found so far is to read the uploaded file to an
image-variable, then using the method of creating thumbnails for the
resizing. Next, I write this to a temp file on the disk, and read the file
back to a byte array in order to insert/update the SQL table.

Now, this works well, and even fast enough, no problem really. I just
irritate myself by the fact that I do the format converting by temp file
saving to the HDD. To perfect this I really want to perform this in memory.
Anynone that has an idea for this?

Bjorn
Mar 8 '07 #1
2 2492
Bjorn,
Have you tried using a MemoryStream? You should be able to save the
image to a MemoryStream then use the ToArray() method (I think that's the
one) of the MemoryStream to generate a byte array.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:BN********************@telenor.com...
Hi.

This story is about uploading jpg's, then resize them to fixed width or
height and storing them to an SQL table.
The only way I have found so far is to read the uploaded file to an
image-variable, then using the method of creating thumbnails for the
resizing. Next, I write this to a temp file on the disk, and read the file
back to a byte array in order to insert/update the SQL table.

Now, this works well, and even fast enough, no problem really. I just
irritate myself by the fact that I do the format converting by temp file
saving to the HDD. To perfect this I really want to perform this in
memory. Anynone that has an idea for this?

Bjorn

Mar 8 '07 #2
Thanks for the tip! MemoryStream did the trick.

Bjorn

"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:e6*************@TK2MSFTNGP06.phx.gbl...
Bjorn,
Have you tried using a MemoryStream? You should be able to save the
image to a MemoryStream then use the ToArray() method (I think that's the
one) of the MemoryStream to generate a byte array.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:BN********************@telenor.com...
>Hi.

This story is about uploading jpg's, then resize them to fixed width or
height and storing them to an SQL table.
The only way I have found so far is to read the uploaded file to an
image-variable, then using the method of creating thumbnails for the
resizing. Next, I write this to a temp file on the disk, and read the
file back to a byte array in order to insert/update the SQL table.

Now, this works well, and even fast enough, no problem really. I just
irritate myself by the fact that I do the format converting by temp file
saving to the HDD. To perfect this I really want to perform this in
memory. Anynone that has an idea for this?

Bjorn


Mar 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by John Smith | last post: by
6 posts views Thread by Luis Arvayo | last post: by
7 posts views Thread by lgbjr | last post: by
3 posts views Thread by grawsha2000 | last post: by
9 posts views Thread by Gregory.A.Book | last post: by
2 posts views Thread by Laurent Navarro | last post: by
10 posts views Thread by =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.