首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >json responseText - ImageView中的Android、JFIF

json responseText - ImageView中的Android、JFIF
EN

Stack Overflow用户
提问于 2015-05-18 19:59:27
回答 1查看 670关注 0票数 1

我必须将从服务器获得的图像显示为ImageView中的json。但是我得到的不是图像的url,而是很多像这样的字符..

代码语言:javascript
复制
����JFIF��C      

 $.' ",#(7),01444'9=82<.342��C           

2!!22222222222222222222222222222222222222222222222222����"��   
���}!1AQa"q2���#B��R��$3br�  
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����

我猜这是Image的原始数据或JFIF。我搜索了stackoverflow,但只能找到从base64转换过来的,或者显示来自url的图片。

如何从中获取图像并将其显示在ImageView中。

致以问候。

EN

回答 1

Stack Overflow用户

发布于 2015-05-19 17:52:42

我不需要将响应转换为Base64。只需将其转换为位图,并将其设置为ImageView。由于我缺乏知识,这是一个非常愚蠢的问题。希望我的代码能在将来帮助别人

代码语言:javascript
复制
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();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30302658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档