Converting image to byte array

Discussion in 'ASP .Net' started by Bjorn Sagbakken, Mar 8, 2007.

  1. 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
    Bjorn Sagbakken, Mar 8, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    Mark Fitzpatrick, Mar 8, 2007
    #2
    1. Advertising

  3. Thanks for the tip! MemoryStream did the trick.

    Bjorn

    "Mark Fitzpatrick" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>

    >
    >
    Bjorn Sagbakken, Mar 10, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGVhc3Vu?=

    Conversion issue: Image>Byte array>Image

    =?Utf-8?B?RGVhc3Vu?=, Jul 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    878
    =?Utf-8?B?RGVhc3Vu?=
    Jul 14, 2005
  2. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,206
    Roedy Green
    Aug 5, 2003
  3. Kirby
    Replies:
    3
    Views:
    624
    Kirby
    Oct 8, 2004
  4. cryptogirl
    Replies:
    5
    Views:
    24,813
    cryptogirl
    Feb 25, 2006
  5. Replies:
    20
    Views:
    9,696
    licebmi
    Sep 7, 2009
Loading...

Share This Page