This is a part of my Activity:
private ImageView mImageView;
private int resource;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
resource = getIntent().getIntExtra("res", -1);
Matrix initMatrix = new Matrix();
mImageView = new ImageView(getApplicationContext());
mImageView.setScaleType( ImageView.ScaleType.MATRIX );
mImageView.setImageMatrix( initMatrix );
mImageView.setBackgroundColor(0);
mImageView.setImageResource(resource);
}
I try to display an image within an ImageView using a matrix as scale type (I want to add multitouch later). But before user starts interaction i want the image to be centered and fit inside the ImageView. I already found answers concerning how to solve it but there is one problem for me: to make image centered using matrix I need to know its width and height. Is there any way of getting image size when all you have is int resource ?
BitmapFactory.Options dimensions = new BitmapFactory.Options(); dimensions.inJustDecodeBounds = true;
to just decode the image dimensions without actually loading the bitmap into memory. – Defection