[問題] outputStream 連續寫入大量圖片 crash

看板AndroidDev作者 (skill)時間11年前 (2014/06/26 15:37), 11年前編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
各位大大好 我用 output stream 將 bitmap 輸出成 jpg 圖片檔 在單張輸出的情況下,完美成功了 但是當我大量輸出好幾張(10幾張) jpg 圖片檔時 立馬就crash了 我以為是我沒有用成 thread的關係 但用thread來做這件事情的時候卻是一樣的結果 請問要怎樣辦到輸出大量 bitmap 成圖片檔案的方法呢? 謝謝! 以下是我的程式碼 Thread thread = new Thread( new Runnable(){ public void run(){ Bitmap[] photos = (很多bitmaps); for( int i=0; i<photos.length;++i){ File photoFile = new File("sdcard/"+i+".jpg"); try{ FileOutputStream out = new FileOutputStream(photoFile); photos[i].compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); } } } }); thread.start(); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.21.125.247 ※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1403768254.A.ADA.html ※ 編輯: issuemylove (211.21.125.247), 06/26/2014 15:38:01

06/26 16:23, , 1F
是瞬間app閃掉,沒有錯誤訊息
06/26 16:23, 1F

06/26 17:36, , 2F
...原因是out of memory已解決...QQ 永遠的痛
06/26 17:36, 2F
文章代碼(AID): #1Jgys-hQ (AndroidDev)