Question: In my code I have an `Image View` in my XML layout and I keep changing the source image for this in my code. Now I want to know the width and height of the generated image each time.

I tried using `getWidth()`, `getHeight(),` `getMeasuredWidth(),` and `getMeasuredHeight()`, but they all return 0.

How can I get this?

Answer: 
try this code 

```
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    public boolean onPreDraw() {
        iv.getViewTreeObserver().removeOnPreDrawListener(this);
        finalHeight = iv.getMeasuredHeight();
        finalWidth = iv.getMeasuredWidth();
        tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
        return true;
    }
});

```

it's really working...
The way you make **reference to the image object** is wrong. That's why you are given zero all the time. first create a bitmap object from imageview and get the width and height from it.

When taken a image from cam I do the following and it works like a charm.

```
Bitmap image2 = (Bitmap) data1.getExtras().get("data");
double width = Double.valueOf(image2.getWidth());
Log.v("WIDTH", String.valueOf(width));
double height = Double.valueOf(image2.getHeight());
Log.v("height", String.valueOf(height));

```

Hope it helps for you.