2013-07-24 9 views
14

muszę uzyskać szerokość i wysokość bitmapy, ale stosując ten daje Spośród wyjątkiem pamięci:Android - szerokość i wysokość bitmapy bez ładowania to

Resources res=getResources(); 
    Bitmap mBitmap = BitmapFactory.decodeResource(res, R.drawable.pic); 
    BitmapDrawable bDrawable = new BitmapDrawable(res, mBitmap); 

    //get the size of the image and the screen 
    int bitmapWidth = bDrawable.getIntrinsicWidth(); 
    int bitmapHeight = bDrawable.getIntrinsicHeight(); 

czytam rozwiązanie w kwestii Get bitmap width and height without loading to memory ale jaki byłby tutaj inputStream?

+0

od ur obrazu jest duża, aby załadować do pamięci – KOTIOS

+0

Pomyślałem, że zbyt .. Stąd pytanie, jak uzyskać dane bez ładowania w pamięci – Gooey

Odpowiedz

15

musisz określić niektóre BitmapFactory.Options także:

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

bDrawable nie będzie zawierać żadnych bitmapy tablicę bajtów. Zrobione z here: Setting the inJustDecodeBounds property to true while decoding avoids memory allocation, returning null for the bitmap object but setting outWidth, outHeight and outMimeType. This technique allows you to read the dimensions and type of the image data prior to construction (and memory allocation) of the bitmap.

+2

decodeResource zwróci wartość null, jeśli options.inJustDecodeBounds = true; Możesz więc pominąć przypisanie 'Bitmap bDrawable = BitmapFactory.de'. Również odpowiedź jest błędna. musisz dostać widht i heigh od opcji – Blackbelt

Powiązane problemy