简体   繁体   中英

How to get the scaled width/height in imageview after postscale()

I have a code which allow user to pinch-zoom some images on the screen. I use AbsoluteLayout and imageviews to display the images. In order to achieve this, I made those imageviews have full width/height to its parent. Then when user touch a point, I will detect which image is under that point area, and use bringChildToFront() so it has focus for onTouch() event. When user make a pinch-zoom, I use matrix and its postScale() method, using this code android imageView: setting drag and pinch zoom parameters

Now, what makes me confuse is, how to get the current width/height of the image after postScale()? I've tried:

  1. getDrawable().getIntrinsicHeight() <-- didnt work. It's always return the original width/height
  2. getDrawable().getBounds().width() <-- same as above
  3. getDrawingCache().getWidth() <-- this just returns the width/height of the imageview

So, what is the appropriate way to achieve this? Thanks.

-ri

Ri-

Here is my solution for the same problem that I had using the Pinch zoom/Drag pan. You can adapt it to your own needs. I put this inside the zoom portion of the MotionEvent.Action_Move

 else if (mode ==ZOOM){
            float newDist = spacing(event);
            if(newDist > 10f){
                int height;
                int width;
                matrix.set(savedMatrix);
                float scale = newDist/oldDist;
                matrix.postScale(scale,scale,mid.x,mid.y);
                setImageMatrix(matrix);
                height = (int)(ivViewPoint.y * scale);
                width = (int)(ivViewPoint.x * scale);
                ivViewPoint = new Point(width,height);


            }

Hope that helps out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM