By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,930 Members | 633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,930 IT Pros & Developers. It's quick & easy.

Problem encoding/decoding image

P: n/a

I'm trying to use POST an image to a web page with WebRequest/WebResponse.
Only problem is that I must be making an error somewhere in the
encoding/decoding process. I've pasted below a bit of sample code that
basically shows how I am encoding and then decoding the binary image. Many
thanks if you can point out what I am doing wrong... thanks, Slade Smith
Image bmp =context.GetImage();
Stream stream=new MemoryStream();

//save image as a jpg file. "test.jpg" will open fine when I try it....
bmp.Save("c:\\temp\\test.jpg",System.Drawing.Imagi ng.ImageFormat.Jpeg);
bmp.Save(stream,System.Drawing.Imaging.ImageFormat .Jpeg);

//encode the image to prepare it for a transfer via a POST
int imgLen = (int)stream.Length;
byte[] imgBinaryData = new byte[imgLen];
int n = stream.Read(imgBinaryData,0,imgLen);
string s = Convert.ToBase64String(imgBinaryData);

//I will be uploading the file here, and the code after this
//will be running on the server...

//trying just to reverse the encoding process and save the file,
//but something has gone horribly wrong, and none of my imaging
//programs will open "test2.jpg" when I try it. Must be corrupted.
Stream f=File.Create("c:\\temp\\test2.jpg");
imgLen = imgBinaryData.Length;
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

Refer to :

Using WebClient make it more easier.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.