Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I need to upload a image from Android mobile through Webservice. I have to convert a image to byte array and then send to webservice, after that i receive that byte array i convert into image and then store to DataBase. But i'm getting "Parameter is not valid" Error.

C#
public static void ImageToByteArrayFromFilePath(string str)
{
   byte[] byteArrayIn = File.ReadAllBytes(str);
   MemoryStream ms = new MemoryStream(byteArrayIn); // Here I'm getting 'Parameter is not valid'
   ms.Seek(0, SeekOrigin.Begin);
   System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
   img.Save("C:\\Users\\Guest\\Desktop\\NewImg.jpg");
}
Posted
Comments
Suvabrata Roy 4-Jun-14 0:50am    
your image input was in string format ?
ridoy 4-Jun-14 4:22am    
Care about your image path,string str. Make sure you have an absolute path of your selected image.

1 solution

1.The method File.ReadAllBytes() parameter is the path to the file, and this method read all bytes from the given file. So check if ImageToByteArrayFromFilePath parameter is a real file path like is expected to be.

2.If this method is trying to do like its name said, the last 3 line from your method above should be there, and it should return a byte array not void!

So what exactly are you trying to do in this method?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900