如何从URI中获取位图?如何从URI中获取Bitmap对象(如果我成功地将它存储在/data/data/MYFOLDER/myimage.png或file///data/data/MYFOLDER/myimage.png在我的应用程序中使用它?有没有人知道如何做到这一点?
3 回答
Helenr
TA贡献1780条经验 获得超3个赞
. . 重要信息:请参见下面@MarkIngram和@pjv的回答以获得更好的解决方案。 . .
public Bitmap loadBitmap(String url){ Bitmap bm = null; InputStream is = null; BufferedInputStream bis = null; try { URLConnection conn = new URL(url).openConnection(); conn.connect(); is = conn.getInputStream(); bis = new BufferedInputStream(is, 8192); bm = BitmapFactory.decodeStream(bis); } catch (Exception e) { e.printStackTrace(); } finally { if (bis != null) { try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return bm;}
幕布斯7119047
TA贡献1794条经验 获得超8个赞
protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Uri imageUri = data.getData(); Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri); }}
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false); Bitmap region = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);
- 3 回答
- 0 关注
- 596 浏览
添加回答
举报
0/150
提交
取消