473,796 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2686
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******** ************@te lenor.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******@fitzm e.comwrote in message
news:e6******** *****@TK2MSFTNG P06.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******** ************@te lenor.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
3866
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 pixel. I need a way to save this this byte array as a gif. Does anyone have any suggestions???
8
4568
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 XML, and embedded the array as some child element in an xml file, i.e.: <Mask>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAAAAEAAQAAAAAAQAAAAAAAAAAAAA AA AAAAAAAAAAAAAAAA////AP//AAD//wAA//8AAP//AAD/7wAA//cAALtzAABVeQAAVUAAAFVA...
10
7408
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 recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
1
1987
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..) Now, because of this I save normal html content also in binary format in the Image field.
6
41624
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 the following (when clicking in a button): MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //
7
11641
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 is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
3
6661
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 memStream.Write(bytes,0.bytes.length)
9
30523
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. How can I convert the sets of 4 bytes to floats? Thanks, Greg Book
2
10354
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 tried to use the MetaFile class. byte data; (...) // Creating the RAW image through the DLL call. MemoryStream memoryStream = new MemoryStream(data);
10
10727
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 return the combined tif image object. Thnks in advance Rinu G P
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.