如何从android中的inputstream(base64 String)获取位图图像?

时间:2016-06-20 12:14:46

标签: java android bitmap inputstream

如何从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;
}

1 个答案:

答案 0 :(得分:-1)

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

ByteArrayInputStream用于工厂