|
-
November 14th, 2006, 11:29 AM
#1
Please help - Convert Image file to bytes
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
-
November 14th, 2006, 12:05 PM
#2
Re: Please help - Convert Image file to bytes
in asp.net 1.1 i use HttpPostedFile and use the "InputStream.Read" method of it .
something like this
Code:
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
rate my posts!
mcm
-
November 14th, 2006, 01:17 PM
#3
Re: Please help - Convert Image file to bytes
Appreciate the response, but i dont think it helps tho,
any other suggestions pls
-
November 14th, 2006, 01:24 PM
#4
Re: Please help - Convert Image file to bytes
 Originally Posted by Bobski
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:
Code:
foreach(Byte b in File.ReadAllBytes(@"c:\test\sunset.jpg"))
Console.Write("{0} ", b.ToString("X2"));
Jason Isom
.NET 2.0 / VS2005 Developer
-
November 14th, 2006, 02:40 PM
#5
Re: Please help - Convert Image file to bytes
Code:
byte[] bytes = null;
using( MemoryStream ms = new MemoryStream() ) {
myBmp.Save(ms, ... );
ms.Seek(0,0);
bytes = ms.ToArray();
}
// bytes contains the image
-
November 14th, 2006, 06:35 PM
#6
Re: Please help - Convert Image file to bytes
***********************
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|