我必须将从服务器获得的图像显示为ImageView中的json。但是我得到的不是图像的url,而是很多像这样的字符..
����JFIF��C
$.' ",#(7),01444'9=82<.342��C
2!!22222222222222222222222222222222222222222222222222����"��
���}!1AQa"q2���#B��R��$3br�
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����我猜这是Image的原始数据或JFIF。我搜索了stackoverflow,但只能找到从base64转换过来的,或者显示来自url的图片。
如何从中获取图像并将其显示在ImageView中。
致以问候。
发布于 2015-05-19 17:52:42
我不需要将响应转换为Base64。只需将其转换为位图,并将其设置为ImageView。由于我缺乏知识,这是一个非常愚蠢的问题。希望我的代码能在将来帮助别人
HttpClient httpClient = ServiceHelper.getHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(RestApiPaths.GET_PROFILE_PICTURE);
try {
HttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
inputStream = entity.getContent();
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imageView.setImageBitmap(emergencyCardPhoto);
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
}
catch(ClientProtocolException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}https://stackoverflow.com/questions/30302658
复制相似问题