使用Webservices从Android上传图像 [英] Image Upload from android using Webservices

查看:84
本文介绍了使用Webservices从Android上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要通过Webservice从Android手机上传图片。我必须将图像转换为字节数组,然后发送到webservice,之后我收到该字节数组,我转换成图像,然后存储到DataBase。但是我得到参数无效错误。



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.

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");
}

推荐答案

1.方法 File.ReadAllBytes()参数是文件的路径,此方法读取给定文件中的所有字节。因此,检查 ImageToByteArrayFromFilePath 参数是否是预期的真实文件路径。



2.如果这种方法正试图像它的名字那样说,你上面的方法的最后3行应该在那里,它应该返回一个字节数组而不是无效!



那么你想用这种方法做什么呢?
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?


这篇关于使用Webservices从Android上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆