Android - width and height of bitmap without loading it

后端 未结 2 1521
渐次进展
渐次进展 2021-01-04 04:41

I need to get the width and height of a bitmap but using this gives an out of memory exception:

    Resources res=getResources();
    Bitmap mBitmap = Bitmap         


        
2条回答
  •  春和景丽
    2021-01-04 05:02

    Use this

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
    int imageHeight = options.outHeight;
    int imageWidth = options.outWidth;
    

    see http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

提交回复
热议问题