我有一個應用程序,它從文件系統繪製圖像到屏幕,像這樣:抓「的RuntimeException:畫布:企圖拉攏過大......」
Bitmap image = BitmapFactory.decodeFile(file.getPath());
imageView.setImageBitmap(image);
如果圖像是非常大的我見此錯誤:
java.lang.RuntimeException: Canvas: trying to draw too large(213828900bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
...
堆棧未達到我的代碼。我怎樣才能捕捉到這個錯誤?還是有更合適的方式將圖像繪製到imageView
可以避免此錯誤?
它不保留寬高比,我們不知道原始位圖的大小是多少。 –
編輯反思 – Zoe