Android. Obtaining image size from it's resource id

前端 未结 2 1506
滥情空心
滥情空心 2020-12-15 04:15

This is a part of my Activity:

private ImageView mImageView;
private int resource;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.on         


        
2条回答
  •  一生所求
    2020-12-15 05:05

    For anyone that didn't read dmon's comment. The code to do this looks like this:

    final Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(), R.drawable.your_photo, opt);
    
    opt.outHeight; // height of resource
    opt.outWidth; // width of resource
    

提交回复
热议问题