473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

image upload problem

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
2 3644


"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lawrence | last post by:
I've been using the following function (yes, it is inelegant, what can I say, I wrote it a long time ago) to upload images. Haven't had a problem with it for at least a year, and I don't recall...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: Paul Hamlington | last post by:
Hello, I've been programming in ASP for a little while now and quite an advanced user, but I have come across an unusual problem in which I need assistance. I have built my own image upload,...
2
by: Gary \(Girish\) | last post by:
Hello: I am using SA-FileUp to enable members to upload their product images to my ISP sever. When member uploaded a new image file, the file name is replaced with the member ID and the old file...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
2
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it...
4
by: Muddasir | last post by:
Hi.. i am having a strange problem.......the problem is i am trying to upload a file and to store it in db....when the file got stored in db...it got converted into black and white image and...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.