我正在从 blob 类型中获取字节数组,同时存储在 db 中,它适用于小图像,但是当图像大小超过 200kb 时,它会给我一个 outofmemoryerror 错误。我应该怎么做才能克服这样的错误
照片是我的字节数组
ByteArrayInputStream imageStream = new ByteArrayInputStream(photo);
Bitmap theImage= BitmapFactory.decodeStream(imageStream);
Bitmap bitmapScaled = Bitmap.createScaledBitmap(theImage, 100,80, true);
Drawable drawable = new BitmapDrawable(bitmapScaled);
imgPath.setBackgroundDrawable(drawable);
imgPath.setScaleType(ImageView.ScaleType.FIT_END);
Logcat 错误
05-06 15:55:38.871: E/AndroidRuntime(2647): FATAL EXCEPTION: main
05-06 15:55:38.871: E/AndroidRuntime(2647): java.lang.OutOfMemoryError
05-06 15:55:38.871: E/AndroidRuntime(2647): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-06 15:55:38.871: E/AndroidRuntime(2647): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
05-06 15:55:38.871: E/AndroidRuntime(2647): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:549)
05-06 15:55:38.871: E/AndroidRuntime(2647): at com.example.hotelmenu.RevisedMainMenu.displayMenu(RevisedMainMenu.java:655)
05-06 15:55:38.871: E/AndroidRuntime(2647): at com.example.hotelmenu.RevisedMainMenu.onClick(RevisedMainMenu.java:615)