【发布时间】:2015-08-19 06:29:23
【问题描述】:
我正在尝试从电话上的特定文件路径设置图像。文件路径是手机上的照片。文件路径可能如下所示
/storage/emulated/0/Pictures/picture.jpg
这是代码。
Bitmap image = null;
//trying to set the image from filepath
try {
image = BitmapFactory.decodeStream((InputStream) new URL(filepath).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (image == null) {
//This becomes true because the image is not set
Toast.makeText(getApplicationContext(),"image == null",Toast.LENGTH_LONG).show();
}
最后没有设置图片。
【问题讨论】:
-
是
URL还是URI? -
最好使用
AsyncTask从url下载图片。 -
图片在手机上,不在网上
-
你能发帖
imgurl吗?它实际上是一个文件路径。不是吗? -
使用
Bitmap bitmap = BitmapFactory.decodeFile(filePath)
标签: java android android-studio bitmapimage