473,383 Members | 1,874 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,383 software developers and data experts.

saving an image from a byte array

I am saving image files from my website using the downloaddata on the web
client. This gives me a byte array, which I am then saving to a file with
the following code:

' Create the new, empty data file.
If File.Exists(ImgDest) Then
Console.WriteLine("{0} already exists!", ImgDest)
Return
End If
Dim fs As New FileStream(ImgDest, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
w.Write(ImgArray)
w.Close()
fs.Close()

This works, in that I end up with the file(s) on my machine, but if I try
and open them they come up as invalid. Any clues? Am I missing a step to do
with image headers or something?
James.
Nov 21 '05 #1
3 3502
James,

Have a look at this sample on our website.

http://www.windowsformsdatagridhelp....7-e68d238952a5

I hope this helps,

Cor
Nov 21 '05 #2

"JamesB" <ja****@jmb.is-a-geekWhoDoesntLikeSpam.com> wrote in message
news:42***********************@news.zen.co.uk...
I am saving image files from my website using the downloaddata on the web
client. This gives me a byte array, which I am then saving to a file with
the following code:

' Create the new, empty data file.
If File.Exists(ImgDest) Then
Console.WriteLine("{0} already exists!", ImgDest)
Return
End If
Dim fs As New FileStream(ImgDest, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
w.Write(ImgArray)
w.Close()
fs.Close()

This works, in that I end up with the file(s) on my machine, but if I try
and open them they come up as invalid. Any clues? Am I missing a step to
do with image headers or something?
James.


Since it's binary data you are writing, I would use the BinaryWriter. But,
since it's an image, I would actually read the byte array into a
MemoryStream, create an Image class instance, then call it's "Save" method.

Mythran

Nov 21 '05 #3

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:eb*************@TK2MSFTNGP09.phx.gbl...


Since it's binary data you are writing, I would use the BinaryWriter. But, since it's an image, I would actually read the byte array into a
MemoryStream, create an Image class instance, then call it's "Save" method.

Thanks for both replies- turns out after more checking my method did
actually work... there was a bug in the way I was building my url from other
places in the app that I hadn't spotted!
I'll do some more testing and if it does give more problems I'll look into
the suggestions you've both given.
Thanks
James
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CodeRazor | last post by:
I'm unfamiliar with image manipulation using c#. How can i resize a jpg that currently exists in a file and save it resized as a new file. The examples i've found have been a bit misleading for...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
3
by: andy_ro | last post by:
Hi group, I have an web application where the user can upload a pdf file. This file is stored in a table, in a column of type ntext. The user can later request the content of this column, and...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
5
by: Dav | last post by:
Hi all, I am using these code to save Image to database: Dim fs As FileStream = New FileStream(filename, _ FileMode.OpenOrCreate, FileAccess.Read) Dim rawData() As Byte = New Byte(fs.Length) {}...
5
by: Keith G | last post by:
VS2003 using VB.Net I want to be able to save drawing path data in a database. If I store the Points array for each GraphicsPath I can then reproduce (in this case) filled polygons at run time....
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
3
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
1
Sl1ver
by: Sl1ver | last post by:
i've got this piece of coding. i need help with opening a picture box and then saving it as OLE Object in access DB How would i massage this code tho fit in? try { //save image to byte...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.