Hi,
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.GetIma ge();
Stream stream=new MemoryStream();
//save image as a jpg file. "test.jpg" will open fine when I try it....
bmp.Save("c:\\t emp\\test.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg);
bmp.Save(stream ,System.Drawing .Imaging.ImageF ormat.Jpeg);
//encode the image to prepare it for a transfer via a POST
int imgLen = (int)stream.Len gth;
byte[] imgBinaryData = new byte[imgLen];
int n = stream.Read(img BinaryData,0,im gLen);
string s = Convert.ToBase6 4String(imgBina ryData);
//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.
imgBinaryData=C onvert.FromBase 64String(s);
Stream f=File.Create(" c:\\temp\\test2 .jpg");
imgLen = imgBinaryData.L ength;
f.Write(imgBina ryData,0,imgLen );
f.Close();
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.GetIma ge();
Stream stream=new MemoryStream();
//save image as a jpg file. "test.jpg" will open fine when I try it....
bmp.Save("c:\\t emp\\test.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg);
bmp.Save(stream ,System.Drawing .Imaging.ImageF ormat.Jpeg);
//encode the image to prepare it for a transfer via a POST
int imgLen = (int)stream.Len gth;
byte[] imgBinaryData = new byte[imgLen];
int n = stream.Read(img BinaryData,0,im gLen);
string s = Convert.ToBase6 4String(imgBina ryData);
//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.
imgBinaryData=C onvert.FromBase 64String(s);
Stream f=File.Create(" c:\\temp\\test2 .jpg");
imgLen = imgBinaryData.L ength;
f.Write(imgBina ryData,0,imgLen );
f.Close();
Comment