Android位图图像大小

Vin*_*oth 6 size android bitmap

我正在从网上下载图像,我使用Gallery小部件来显示图像.

如果下载的图像大小很大,我的应用程序会崩溃,并显示以下日志.

"E/GraphicsJNI( 3378): VM won't let us allocate 5591040 bytes"
Run Code Online (Sandbox Code Playgroud)

我想缩小下载的图像大小,只有当图像大小超过它会使应用程序崩溃的程度时.我已经编写了缩小图像大小的代码,但我不知道如何找到位图大小,以便我可以决定是否缩放

   BitmapFactory.Options o = new BitmapFactory.Options();
   o.inSampleSize = 2;
   Bitmap bit = BitmapFactory.decodeStream(inputStream,null,o);
   Bitmap scaled = Bitmap.createScaledBitmap(bit, 200, 200, true);
   bit.recycle();
   return scaled;
Run Code Online (Sandbox Code Playgroud)

Asa*_*ahi 3

使用inJustDecodeBounds字段BitmapFactory.Options获取位图尺寸。