PinchToZoom
PinchToZoom copied to clipboard
Not able to navigate a zoomed image. Swiping takes to second image instead of showing the section of zoomed image
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
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!
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.
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)){