Android,json 中的 JFIF responseText - ImageView

标签 android

我必须在 ImageView 中以 json 格式显示从服务器获取的图像。但是我得到的不是图片网址,而是很多这样的字符..

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

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

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

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

问候。

最佳答案

我不必将响应转换为 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();
}

关于Android,json 中的 JFIF responseText - ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30302658/

相关文章:

Android - 多个 AAR 变体 Nexus 上传

Android 4.1.2 上的 Android 应用程序- 布局怪异

java - 使用 Listview 显示列表时出错

android-support-v7-appcompat 支持库不适用于 android 2.2

java - inflater.inflate() 方法调用时出现 InflateException

android - 空列表框显示在 ListView 中

android - 如何以编程方式在 Android 中使用 OpenGL ES 2.0 动态绘制虚线?

android - 在哪里可以找到 Android 补丁?

java - 未为Notification.builder定义方法build()

Android Proguard 和 FirebaseListAdapter 冲突