안드로이드에서 Uri로부터 비트맵을 추출하는 방법
조회수 2174회
Uri에서 비트맵 객체를 받아오려면 어떻게 해야하죠? 받아와서 비트맵을 저장할 경우 /data/data/MYFOLDER/myimage.png 나 file///data/data/MYFOLDER/myimage.png 이 두 경로를 사용할것 같은데
여러가지 방법을 시도해봤는데 안돼요. 아시는 분 계신가요?
1 답변
-
이렇게 해보세요.
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; }
단, AsyncTask 같은 쓰레드로 돌리셔야됩니다.
댓글 입력