Take the 2-minute tour ×

I need to get image dimensions only from a folder inside another folder which is in Assets folder. I have tried some codes but I am unable to save memory i.e I don't want to load the image into memory I only want to get the dimensions of all files in a folder. Here is the code I am using but this is not memory efficient I don't want to load the bitmaps.

private void getFileNames()
    AssetManager assetManager = mCxt.getAssets();
    InputStream bitmap;
    Bitmap bit;
    Log.d("Jawad"," in Funtion");
    // To get names of all files inside the "Files" folder
    try {
        String[] files = assetManager.list(mFolferPath);

        Log.d("Jawad"," Length "+files.length);
            if(files[i].contains(".png") ||files[i].contains(".jpg"))
                Log.d("Jawad","" +files[i]);
                Log.d("Jawad",""+ " ," +bit.getWidth() + " , " + bit.getHeight());
                bitmap = null;
                bit = null;
    } catch (IOException e1) {
        Log.d("Jawad"," "+e1);

mFolferPath = gfx/decoration/biscuits

This code is giving me the dimensions but again the problem is I dont want to load them into memory. Please help me with this. Thanks

share|improve this question
try using decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) where pass with inJustDecodeBounds = true for option –  Sudar Nimalan May 13 '13 at 6:58
add comment

1 Answer

up vote 1 down vote accepted

To get only the dimensions of an image decode it with BitmapFactory.Options.inJustDecodeBounds set to true.

BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
Bitmp_Options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(bitmap, null, options);

int currentImageHeight = Bitmp_Options.outHeight;
int currentImageWidth = Bitmp_Options.outWidth;

see here

share|improve this answer
Thanks it worked, :) –  Jawad Amjad May 13 '13 at 9:57
add comment

Your Answer


