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

image upload problem

P: n/a
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 ;).

Apr 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a


"ge**********@gmail.com" wrote:
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 ;).

May 12 '07 #2

P: n/a
I found this website, which I have found works great!

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

I hope this helps
deDogs
"ge**********@gmail.com" wrote:
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 ;).

May 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.