Connecting Tech Pros Worldwide Help | Site Map

image upload problem

geertolaerts@gmail.com
Guest
 
Posts: n/a
#1: Apr 25 '07
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.MemoryStream ms =
new System.IO.MemoryStream(ImgIn);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);

b.Save("test.png",
System.Drawing.Imaging.ImageFormat.Png);

return true;
}
and the code at client side:
private void button1_Click(object sender, EventArgs e)
{
string dir = System.Environment.CurrentDirectory;
localhost.Service t2 = new localhost.Service();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.Environment.CurrentDirectory = dir;
string ImageFilename = openFileDialog1.FileName;
Bitmap bmpt = new Bitmap(openFileDialog1.FileName);
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(String filename, ImageCodecInfo
encoder, EncoderParameters 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 ;).

=?Utf-8?B?ZGVEb2dz?=
Guest
 
Posts: n/a
#2: May 12 '07

re: image upload problem




"geertolaerts@gmail.com" wrote:
Quote:
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.MemoryStream ms =
new System.IO.MemoryStream(ImgIn);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);
>
b.Save("test.png",
System.Drawing.Imaging.ImageFormat.Png);
>
return true;
}
and the code at client side:
private void button1_Click(object sender, EventArgs e)
{
string dir = System.Environment.CurrentDirectory;
localhost.Service t2 = new localhost.Service();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.Environment.CurrentDirectory = dir;
string ImageFilename = openFileDialog1.FileName;
Bitmap bmpt = new Bitmap(openFileDialog1.FileName);
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(String filename, ImageCodecInfo
encoder, EncoderParameters 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 ;).
>
>
=?Utf-8?B?ZGVEb2dz?=
Guest
 
Posts: n/a
#3: May 12 '07

re: image upload problem


I found this website, which I have found works great!

http://blogs.msdn.com/agilemonkey/ar...-with-axd.aspx

I hope this helps
deDogs


"geertolaerts@gmail.com" wrote:
Quote:
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.MemoryStream ms =
new System.IO.MemoryStream(ImgIn);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);
>
b.Save("test.png",
System.Drawing.Imaging.ImageFormat.Png);
>
return true;
}
and the code at client side:
private void button1_Click(object sender, EventArgs e)
{
string dir = System.Environment.CurrentDirectory;
localhost.Service t2 = new localhost.Service();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.Environment.CurrentDirectory = dir;
string ImageFilename = openFileDialog1.FileName;
Bitmap bmpt = new Bitmap(openFileDialog1.FileName);
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(String filename, ImageCodecInfo
encoder, EncoderParameters 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 ;).
>
>
Closed Thread