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

Not able to navigate a zoomed image. Swiping takes to second image instead of showing the section of zoomed image #17

Open
ndubbaka opened this issue May 2, 2019 · 3 comments

Comments

@ndubbaka
Copy link

ndubbaka commented May 2, 2019

I am not able to navigate a zoomed image. Swiping takes to second image instead of showing the section of the zoomed image.
Bug explained in this video at https://www.youtube.com/watch?v=_9XjgVCqIOg&t=300

Note that I should also be able to listen to longclick on a zoomed image. Currently I am able to detect longpress using GestureDetector as shown here https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/activities/ViewImageActivity.java#L188

Also I am not able to send the zoomed section to OCR detection(Google firebase ML Kit). I am only able to send the full image at https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/activities/ViewImageActivity.java#L240

@martinwithaar
Copy link
Owner

You can solve this problem by using the following class instead of Android's regular ViewPager: https://github.com/martinwithaar/PinchToZoom/blob/master/pinchtozoom/src/main/java/com/bogdwellers/pinchtozoom/view/ImageViewPager.java

If you don't use the v4 library version of ViewPager you'll have to extend the pager class yourself or if you use an even more exotic view type you'll have to transplant parts of the logic as you see fit.

The sample app that demonstrates the library is included in this project so you could both check out the Play Store listing and the source code to see how you can make things work.

Please let me know if this solved your problem!

@ndubbaka
Copy link
Author

ndubbaka commented May 3, 2019

That ImageViewPager worked great. Thanks @martinwithaar

Also do you know how I can get only the zoomed visible drawable bitmap from imageview? not the entire image. Only the zoomed visible portion.

@ndubbaka
Copy link
Author

ndubbaka commented May 3, 2019

or how to get the zoom scale & calculate relative (x, y) position of touched point?

The problem is OCR gives x, y position of text block from original image. When I zoom it I don't know the x, y position of the zoomed text block that's visible.

Here I am getting the text block x, y from OCR https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/activities/ViewImageActivity.java#L262

Rect boundingRect = tElement.getBoundingBox();
visionTextRectangles.put(boundingRect, tElement.getText());

I am painting a yellow rectangular box surrounding the text word

canvas.drawBitmap(originalBitmap, 0, 0, paint);
canvas.drawRect(boundingRect, paint);

I am looping through all the rectangular yellow painted boxes and finding a match for the box the user just touched. This works if not zoomed. When zoomed the x, y is different and I don't know how to get the relative x, y position of touched point with respect to the original image dimensions.

if(event.getAction() == MotionEvent.ACTION_UP) {
  Iterator it = visionTextRectangles.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry)it.next();
      Rect rect = (Rect)pair.getKey();
      int threshold = 100;
      if(rect.contains(touchX,touchY) || rect.contains(touchX - threshold,touchY - threshold) || rect.contains(touchX + threshold,touchY + threshold)){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants