Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read an image file into a byte stream

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Hey guys,

I have a picture box with an image.

I need to be able to read that image into a byte array.

Any thoughts on how I can accomplish this?

Thanks,

D'Arcy
 
Hi
Here is the code for reading file
Regards
Nouman

Dim fs As New FileStream _
("C:\winnt\Gone Fishing.BMP", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
you can then use MyData to what you want

Nouman Zaheer
Software Engineer
MSR
 
I got it figured out.

I didn't end up putting the binary into xml though. I just added a paramater to my web service of type byte array, and passed that in.

To upload I did this:

Dim ms As New System.IO.MemoryStream
Dim b() As Byte

PictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
ms.Position = 0
ReDim b(ms.Length - 1)
ms.Read(b, 0, ms.Length - 1)

objWService.UploadPic(b)

To fill an image on the server I did this (image is the variable name for the byte array):

Dim memStream As New System.IO.MemoryStream(image)
Dim vehImage As New Bitmap(memStream)
vehImage.Save(Server.MapPath("Images\" & strFileName & ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top