-
이미지 로딩으로 인한 OutOfMemoryException 문제
File fdir = this.getFilesDir(); if(fdir.isDirectory() && !fdir.exists()) { fdir.mkdir(); } File f2 = null; try { f2 = File.createTempFile("test", ".jpg", fdir); if(f2.exists()) { f2.createNewFile(); } } catch (IOException e) { e.printStackTrace(); } { //TODO: image work } BitmapFactory.Options bo = new BitmapFactory.Options(); bo.inJustDecodeBounds = true; InputStream in = null; try { in = new FileInputStream(f2); } catch (FileNotFoundException e) { e.printStackTrace(); } BitmapFactory.decodeStream(in, null, bo); try { in.close(); } catch (IOException e) { e.printStackTrace(); } in = null; {//limit image size final int reqH = 1000, reqW = 1000; if(bo.outHeight > reqH || bo.outWidth > reqW) { int ratioH = Math.round((float)bo.outHeight/(float)reqH), ratioW = Math.round((float)bo.outWidth/(float)reqW); bo.inSampleSize = ratioH < ratioW ? ratioH : ratioW; } } {// Bitmap bm = BitmapFactory.decodeFile(f2.getAbsolutePath(), bo); }
'Android' 카테고리의 다른 글
Android - BroadcastReceiver (0) 2020.07.20 Android - Google Map 적용 (0) 2020.07.19 AndroidStudio - Tab Space 탭키 간격 (0) 2020.07.19 Android - Scoped Storage Mode (0) 2020.07.19 Android - local DBMS, Realm (0) 2020.07.19 Android - local DBMS, SQLite (0) 2020.07.19 Android - ConstrainLayout (0) 2020.07.19 Android - GridLayout (0) 2020.07.19