BitmapFactory.decodeStream with inJustDecodeBounds=true always return 100×100

This is my android code:

InputStream input = getAssets().open("photo.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, null, options);
System.out.println("### img size: " + options.outWidth + "x" + options.outHeight);

But I found no matter how big of my image, it always print:

### img size: 100x100

Where is wrong?


UPDATE

It works fine after I re-deploying my application, but I modified nothing. It’s strange but I want to keep this question here, maybe it will appear someday again.

Answer

//Read Bitmap Dimensions and Type

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

Ref here:

//you didn’t assigned object name

InputStream input = getAssets().open("photo.jpg");

The BitmapFactory class provides several decoding methods (decodeByteArray(), decodeFile(), decodeResource(), etc.) for creating a Bitmap from various sources.

Leave a Reply

Your email address will not be published. Required fields are marked *