question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to scale (zoom and move) to x,y coordinates of Bitmap in PhotoVIew?

See original GitHub issue

At start I have Bitmap and x,y point on the Bitmap.

How to scale, zoom and move image to x,y coordinates of the bitmap?


    int bitmapWidth = bitmap.getWidth();//2418
    int bitmapHeight = bitmap.getHeight();//1889
    float x = 1209f;
    float y = 944f;

    float targetScale = 4f;    
    attacher.setScale(targetScale, x,y, false);//it doesnt work


Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
antoineFraucommented, Jul 23, 2019

Ok so I finally understand and make it work. That doesn’t work because I used the animation on the setScale, which was call in an other thread.

mImageView.post(new AnimatedZoomRunnable(getScale(), scale, focalX, focalY));

And in the same time I tried to simulate the movement to re-center the point int the center of the screen.

var event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, focalX, focalY, 0)
mPhotoView.dispatchTouchEvent(event)

val centerImageX = showResultCoinDetectionPhotoView.displayRect.centerX()
val centerImageY = showResultCoinDetectionPhotoView.displayRect.centerY()

var event = event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, centerImageX, centerImageY, 0)
mPhotoView.dispatchTouchEvent(event)

But when this part of the code get executed the scale isn’t finished, so the movement can’t happened cause the image is full sized and we can’t drag a full size image.

So to resolve that I remove the animation.

mPhotoView.setScale(5f, focalX, focalY, false)

An other solution could be use a callback or coroutine for the scaling and in the same time do the move, cause we will be in a sequential code part. But the AnimatedZoomRunnable is in another thread so we will go till the :

if (animate) {
       mImageView.post(new AnimatedZoomRunnable(getScale(), scale, focalX, focalY));
}

And go back to the next line of the coroutine.

So actually I don’t have more option to do that. Maybe place a button to be able to center the point in the middle of the screen like in GoogleMap and execute the “simulating drag” when user click ?

Or does there is a way to get notify when AnimatedZoomRunnable is finished ?

Let me know if you found something interesting. Thanks.

1reaction
aslansaricommented, Feb 15, 2019

@Kolyall try this, you need to calculate focal points

    int bitmapWidth = bitmap.getWidth();//2418
    int bitmapHeight = bitmap.getHeight();//1889
    float x = 1209f;
    float y = 944f;

    float focalX = x*photoView.getRight()/bitmap.getWidth();
    float focalY = y*photoView.getBottom()/bitmap.getHeight();

    float targetScale = 4f;    
    attacher.setScale(targetScale, focalX, focalY, false);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to scale (zoom and move) to x,y coordinates of Bitmap in ...
First of all you need to convert your coordinates to the PhotoView : int bitmapWidth = bitmap.getWidth();//2418 int bitmapHeight = bitmap.
Read more >
How to scale (zoom and move) to x,y coordinates of Bitmap in ...
At start I have Bitmap and x,y point on the Bitmap. How to scale, zoom and move image to x,y coordinates of the...
Read more >
Enlarge a view using a zoom animation - Android Developers
This lesson demonstrates how to do a touch-to-zoom animation, which is useful for apps ... scale properties (X, Y, SCALE_X, and SCALE_Y).
Read more >
photo_view | Flutter Package - Pub.dev
PhotoView enables images to become able to zoom and pan with user gestures such as pinch, rotate and drag. It also can show...
Read more >
Agisoft Metashape User Manual - Professional Edition ...
To adjust the bounding box manually, use the Resize Region, Move Region and Rotate ... on how to define x and y coordinates...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found