Android的位图图像大小 [英] Android bitmap image size

查看:119
本文介绍了Android的位图图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从下载网页中的图像和我用图库小部件来显示图像。

如果下载的图像尺寸是巨大的,我用下面的日志应用程序崩溃。

 E / GraphicsJNI(3378):虚拟机不会让我们分配5591040字节
 

欲缩小所下载的图像的大小仅当图象的大小是更要的程度,它会崩溃的应用程序。我已经写了code,以缩小图像大小,但我不知道如何找到位图的大小,所以我可以就是否扩大或决定不

  BitmapFactory.Options O =新BitmapFactory.Options();
   o.inSampleSize = 2;
   位图位= BitmapFactory.de codeStream(的InputStream,空,O);
   位图缩放= Bitmap.createScaledBitmap(位,200,200,真正的);
   bit.recycle();
   返回比例;
 

解决方案

使用<一个href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDe$c$cBounds" BitmapFactory.Options inJustDe codeBounds 场>得到位图的尺寸。

I am downloading images from web and i use Gallery widget to display the images.

If the downloaded image size is huge, my application crashes with the below log.

"E/GraphicsJNI( 3378): VM won't let us allocate 5591040 bytes"

I want to scale down the downloaded image size only when the image size is more to an extent that it will crash the app. I have written the code to scale down the image size but i am not sure how to find the bitmap size so i can decide on whether to scale or not

   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;

解决方案

Use inJustDecodeBounds field of BitmapFactory.Options to get bitmap dimensions.

这篇关于Android的位图图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆