【问题标题】:How do i get bitmap image from inputstream(base64 String) in android?如何从 android 中的 inputstream(base64 String) 获取位图图像?
【发布时间】:2016-06-20 12:14:45
【问题描述】:

如何在 Android 中从InputStream(base64 String) 获取位图图像?

下面是我的代码:

protected Bitmap doInBackground(Void... params) {
    Bitmap image;
    URL url1 = null;
    try {
        url1 = new URL("http://sunnyfacemash.atwebpages.com/get.php"); // url 
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try {
         image = BitmapFactory.decodeStream(url1.openConnection().getInputStream());
         return image;
    } catch (IOException e) {
        image = null;
        e.printStackTrace();
    }
    return image;
}

【问题讨论】:

  • 刚刚在浏览器中打开了你的 php url 它正在显示一些字符串是 base64 字符串吗?
  • 是的,它是一个 base64 字符串。我想得到那个字符串并在android中显示图片。
  • this 答案包含转换字符串到基数,反之亦然

标签: java android bitmap inputstream


【解决方案1】:

将流下载到字符串,然后在其上使用Base64.decode 并将其提供给BitmapFactory

工厂使用ByteArrayInputStream

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多