简体   繁体   中英

android problems with pinch to zoom libraries PhotoView and TouchImageView on portrait images

I want to display images and allow pinch to zoom. My app is a blank activity with a linear layout with ImageView on top and under it a horizontal linear layout with some buttons. I have tried both PhotoView and TouchImageView They both have similar problems:

  1. the toolbar menu on right doesn't respond to touch (in 4.4.4 and 4.4.2). It seems to respond in 5.0.2.
  2. photos taken in portrait mode do not display or zoom properly: they only use a portion of the ImageView.

I have looked at the code from TouchImageView and think I can see the answer to problem 2: The routines get the width and height from code like :

float w = getDrawable().getIntrinsicWidth();

To properly display a portrait mode photo in my app I need to do this

imageRotation = getOrientation(photoFilePath);
imgView.setRotation(imageRotation);

This rotates the photo for display, but the intrinsicWidth and intrinsicHeight do not change. So the zooming software has the wrong dimensions. Strange that this has not been caught before. (Maybe it is my mistake.) If I am right then I need to change the code so that the imgView.ROTATION property is tested.

Edit: I can detect rotation and then switch height and width in portrait mode images. This helps a little, but is not enough. There is still unused blank space in the imageview. More work would be needed and this is beyond my skills.

Thanks for any help.

It took me a while to figure this out. My problem was how I rotated the portrait images to get them into the correct orientation on the screen. I used

        imgView.setRotation((float)imageRotation);

That caused the problem! Doing it this way (ie not using the imageView functionality)

    Matrix matrix = new Matrix();
    matrix.postRotate(imageRotation);
    bmp = Bitmap.createBitmap(bmp , 0, 0, bmp .getWidth(), bmp.getHeight(), matrix, true);

worked.

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