Cheney Hester
Cheney Hester

Reputation: 528

Checking a camera or image for pixel size

So I was following this tutorial and it says on the tutorial that it assumes the image is 300px x 300px. How do I figure out how large my image is in terms of px when I have just gotten the image from the camera on the phone (not through an instance if that matters).

Upvotes: 1

Views: 97

Answers (1)

David Manpearl
David Manpearl

Reputation: 12656

The example referenced in the question is opening an existing Bitmap image from the application's resources like this:

Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.image);

How To Get Android Image Bitmap Size

You can determine the width and height of this or any Bitmap with getWidth() and getHeight() as below:

int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();

The complete documentation for Bitmap is here.


Regarding the 300x300 pixel size, the example is forcing those sizes and creating a new Bitmap with the hardcoded values, as below:

int targetWidth = 300;
int targetHeight = 300;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);

Upvotes: 1

Related Questions