在Java服务器获取我从外部服务URL像图片:
In Java server I fetch image from external service URL like:
InputStream in = new java.net.URL(imageWebServiceURL).openStream();
String resultToCleint = org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(IOUtils.toByteArray(in));
然后在我的Android解析它喜欢的:
Then on Android I parse it like:
byte[] imageAsBytes = Base64.decode(resultToCleint.getBytes(), Base64.DEFAULT);
imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
结果:不显示图像,是不是错误/异常既不在服务器上也没有客户端
Result: Image not displayed, ain't errors/exceptions neither on server nor on client.
有什么问题吗?
编辑:在Android上我使用类 android.util.Base64
On android I use class android.util.Base64
谢谢,
至于评论,让我们假设 base64Content
是为Base64字符串从您的Web服务/服务器端应用程序把响应,你可以参考下面的示例code:
As commented, let's assume base64Content
is the base64 string responsed from your web service/server-side app, you can refer to the following sample code:
String base64Content = jsonObject.getString("Base64Content");
byte[] bytes = Base64.decode(base64Content, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
此外,如果你的服务器COM pressed效应初探数据或者通过的的gzip 或放气的,您的客户端应用程序必须DECOM preSS第一的数据。
Moreover, if your server compressed reponse data either by gzip or deflate, your client app must decompress the data first.
希望这有助于!