Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom image smaller than viewport and move it within viewport #69

Closed
angelkoh opened this issue Apr 24, 2017 · 8 comments
Closed

Zoom image smaller than viewport and move it within viewport #69

angelkoh opened this issue Apr 24, 2017 · 8 comments
Labels

Comments

@angelkoh
Copy link

angelkoh commented Apr 24, 2017

the Api does the zoom function amazingly.

Is it possible to go the opposite direction and have a function to shrink the images (make the image smaller than the image view)?

Currently, the image snaps back to the size of the image view when trying to shrink the image.

@alexvasilkov
Copy link
Owner

alexvasilkov commented Apr 24, 2017

Not sure if I understand it correctly, but probably you need to set setFillViewport(false) (which is set to false by default actually, so you should just ensure you are not setting it to true). In this case you should be able to zoom out image to it's original size, if it is smaller than viewport.

If you want to be able to zoom out any image to the size smaller than viewport then it is probably not possible. But in this case, what is your use case?

@angelkoh
Copy link
Author

I'm currently using the GestureViews API in a tracing app.

The user selects an image, and adjusts a template image to the desired size/rotation for tracing on a physical paper. There are times when they want to reduce the template image to a size smaller than the image view.

https://play.google.com/store/apps/details?id=twitch.angelandroidapps.tracerlightbox

@alexvasilkov
Copy link
Owner

Ok, I see. You can try to play around with setMovementArea(int w, int h)

@alexvasilkov
Copy link
Owner

Have you tried setMovementArea method? Any luck?
You can also try to disable any limits using disableBounds().

@angelkoh
Copy link
Author

angelkoh commented May 2, 2017

disableBounds() works, but now it is easy to accidentally 'flip' the shrunken image out of view.

Is there a way to ensure that the image can be shrunk and still be constrained within the view?

@alexvasilkov
Copy link
Owner

Have you tried setMovementArea method? Using it you can choose a smaller area of your screen which will be used to restrict movement and zoom.

In general, your use case seems pretty specific, so I can't see any obvious options how to implement an unlimited zooming within limited area.

You can probably try to hack the way image size is calculated in GestureImageView, so the lib will think that image is bigger than it is and will allow you to zoom it our below min zoom level, but I can't help you here much.

@angelkoh
Copy link
Author

I didn't have much luck with setMovementArea either, because often times users wants to Zoom out instead of shrink the image. so I would need the full area for movement.

disableBounds don't work with in conjunction with setMovementArea also. I'll see if I can hack out something like a "disableZoomBounds + setMovementArea" method.

btw, are there any methods to

  1. detect if an image is entirely outside the viewport and
  2. move the center of the image to the center of the viewport programmatically and
  3. get current zoom level ?

@alexvasilkov
Copy link
Owner

Yes, but it will require some math from you:

  1. Using getController().getState() (image position) and getController().getSettings().getImageW() / getController().getSettings().getImageH() you can compute image's rect in view's coordinates:
state.get(matrix);
rect.set(0, 0, imageW, imageH);
matrix.mapRect(rect);

Then you can just check that image is outside of the view using:

rect.intersects(0, 0, viewW, viewH);

Note, that if image was rotated then this will be a bounded rect around image's rotated rect. So you may need a bit more complicated calculations, if you want to do it 100% correct.

  1. Just calculate dx and dy between image rect center (see above) and viewport center.
    Then you can change image state by:
controller.getState().translateBy(dx, dy);
controller.updateState();

If you want to animate state then:

State end = controller.getState().copy();
end.translateBy(dx, dy);
controller.animateStateTo(end);
  1. state.getZoom().

@alexvasilkov alexvasilkov changed the title Shrink images [enhancement] Zoom image smaller than viewport and move it within viewport Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants