Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Converting image to byte array

Reply
Thread Tools

Converting image to byte array

 
 
Bjorn Sagbakken
Guest
Posts: n/a
 
      03-08-2007
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


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      03-08-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Bjorn Sagbakken
Guest
Posts: n/a
 
      03-10-2007
Thanks for the tip! MemoryStream did the trick.

Bjorn

"Mark Fitzpatrick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert form byte[4] to Int32 while retaining the binary value of the byte array jeff@foundrymusic.com C++ 20 09-07-2009 08:54 PM
Re: how to extend a byte[] array with a null byte? Tom McGlynn Java 4 04-18-2008 11:49 PM
converting a int array to a byte array cryptogirl Java 5 02-25-2006 03:38 PM
Converting a Primative byte array to a Byte array object Kirby Java 3 10-08-2004 03:01 AM
Appending byte[] to another byte[] array Bharat Bhushan Java 15 08-05-2003 07:52 PM



Advertisments