Any app allow user pick picture as background or draw somewhere, it must encount the problem, if user pickup a panoramic photograph or big picture your app must force close, and YOU HAVE NO CHANCE TO PREVENT THE MISTACK, because you can't catch the Exception.
Ok, I just need catch the Exception and tell user we can't load the picture then finish, it too redundant to use Picasso or such library for the additional function, android coding is suffer and I don't want make it more suffer.
finally, I found the code in core.java.android.view.DisplayListCanvas, there is define a max image size with variable MAX_BITMAP_SIZE
private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
You couldn't read the variable in your program, it's define as private(but if you have any way to read the variable please let me know), and here is the part code that throw RuntimeException:
int bitmapSize = bitmap.getByteCount();
if (bitmapSize > MAX_BITMAP_SIZE) {
throw new RuntimeException(
"Canvas: trying to draw too large(" + bitmapSize + "bytes) bitmap.");
}
I just copy the part above, check the size of bitmap in my code, if it over 100M then show message to user the message I mention above then finish.
If your case is the same with me, hope it help you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…