473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2652
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chad | last post by:
I have a one dimensional byte array that stores the pixel information of my image. The image is 8-bit grayscale so each byte in the array holds a value from 0(black) to 255(white) for a single...
8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
1
by: KK | last post by:
Hi, I need to save certain content to SQL server and then use SQL Server indexing facility to search. SQL Server have recomended using Image data type with a filter type (for .htm, .doc etc..)...
6
by: Luis Arvayo | last post by:
Hello, I am trying to convert a jpeg image stored in a PictureBox to a byte array in order to later save it to a database, but I get this error : "Generic Error in GDI+". The source code is...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: grawsha2000 | last post by:
Hi, I'm trying to convert this simple string into image: Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123") Dim memStream as System.IO.MemoryStream Dim img as image ...
9
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats....
2
by: Laurent Navarro | last post by:
Hello, I am using a library which returns a byte containing RAW data, ie all pixels' color values coded in a byte array without header. I would like to save those data into a JPEG file so I...
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.