Hello,
I have a problem with uploading off images to my webservice, i convert
them to a byte[] at client side but something goes wrong when i try to
convert them back to a image at server side.
The webservice code:
[WebMethod]
public bool PutImage(byte[] ImgIn)
{
System.IO.Memor yStream ms =
new System.IO.Memor yStream(ImgIn);
System.Drawing. Bitmap b =
(System.Drawing .Bitmap)Image.F romStream(ms);
b.Save("test.pn g",
System.Drawing. Imaging.ImageFo rmat.Png);
return true;
}
and the code at client side:
private void button1_Click(o bject sender, EventArgs e)
{
string dir = System.Environm ent.CurrentDire ctory;
localhost.Servi ce t2 = new localhost.Servi ce();
if (openFileDialog 1.ShowDialog() == DialogResult.OK )
{
System.Environm ent.CurrentDire ctory = dir;
string ImageFilename = openFileDialog1 .FileName;
Bitmap bmpt = new Bitmap(openFile Dialog1.FileNam e);
Bitmap bmp = new Bitmap(bmpt);
// Create stream....
MemoryStream ms = new MemoryStream();
// save the image to the stream
bmp.Save(ms, ImageFormat.Bmp );
t2.PutImage(ms. GetBuffer());
}
}
the error i get is in the save function of the webservice: A generic
error occurred in GDI+.
at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo
encoder, EncoderParamete rs encoderParams). My code is almost the same
as this: http://www.codeproject.com/soap/ImageUploadWS.asp so it
should work but i don't see what could cause the error. I did put the
right permissions ;).