【发布时间】:2011-09-07 10:54:45
【问题描述】:
如何在 Android 中使用 Web 服务将图像(作为字节数组)上传到服务器?
【问题讨论】:
如何在 Android 中使用 Web 服务将图像(作为字节数组)上传到服务器?
【问题讨论】:
对于肥皂网络服务,您可以使用 ksoap2。还有一个 wsdl>proxy.java 生成器
【讨论】:
**To upload your Image to server, convert a bitmap image to base64 and then send the string. Use the below code**
Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width,
height, matrix, true);
ByteArrayOutputStream baostream = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, baostream);
byte[] byteArrays = baostream.toByteArray();
encode = Base64.encodeBytes(byteArrays);
**and vice-versa**
byte[] decode = Base64.decode(encode);
Bitmap bitmp = BitmapFactory.decodeByteArray(decode, 0,
decode.length);
【讨论】: