Click to See Complete Forum and Search --> : Please help - Convert Image file to bytes
Bobski
November 14th, 2006, 10:29 AM
Hi guys,
How do i go about converting images files like jpeg's in to bytes?
Im doing the work in c#, the .net 2.0 platform, if that makes any difference...
really need some help on this, thanks!
Bobski
mcmcom
November 14th, 2006, 11:05 AM
in asp.net 1.1 i use HttpPostedFile and use the "InputStream.Read" method of it .
something like this
HttpPostedFile theFile = this.myFile.PostedFile;
byte[] uploadData = new Byte[nFileLen]; //nFileLen is the size of the file in bytes
theFile.InputStream.Read(uploadData,0,nFileLen);
//the above line reads the posted file into a byte array called uploadData.
then uploadData has all the bytes in an array, and you can flush it or write it to a new file.
hth,
mcm
Bobski
November 14th, 2006, 12:17 PM
Appreciate the response, but i dont think it helps tho,
any other suggestions pls
Jason Isom
November 14th, 2006, 12:24 PM
Hi guys,
How do i go about converting images files like jpeg's in to bytes?
Im doing the work in c#, the .net 2.0 platform, if that makes any difference...
really need some help on this, thanks!
Bobski
Is the file on your computer? You could try the following:
foreach(Byte b in File.ReadAllBytes(@"c:\test\sunset.jpg"))
Console.Write("{0} ", b.ToString("X2"));
MadHatter
November 14th, 2006, 01:40 PM
byte[] bytes = null;
using( MemoryStream ms = new MemoryStream() ) {
myBmp.Save(ms, ... );
ms.Seek(0,0);
bytes = ms.ToArray();
}
// bytes contains the image
Bobski
November 14th, 2006, 05:35 PM
***********************
Is the file on your computer? You could try the following:
Code:
foreach(Byte b in File.ReadAllBytes(@"c:\test\sunset.jpg"))
Console.Write("{0} ", b.ToString("X2"));
*************************
Yeh mate this seems to work, thx.
Im basically trying to change it into bytes so i can send it over a bluetooth connection using OBEX to a mobile device. All i need to know now is how to convert this back to an image so i can display it on the phone. Oh how i love programming ;-)
Thanks
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.