Can anyone explain the Matrix (Mr. Anderson)?

I am new to manual image manipulation, so please bear with me.

I have an image that I allow the user to shrink / grow and move around.

The main behavior works fine. However, I need to be able to capture everything that is in the “viewport” (the visible rectangle of the clipping region) and save it as a separate raster image.

Before I can do this, I need to get a fix on where the image is actually and what is displayed. It turned out to be more complicated than I could have imagined.

My problem is that the Matrix documentation is absurdly foggy, and I get lost as to how I can measure the coordinates and dimensions of my converted image. As I see it, X, Y images remain constant, even when the user compresses / enlarges it. So, although it reports that it is equal to 0.0, it displays (say) 100 100. And the only way to get these coordinates is to do a rather ugly calculation (again ... I probably don't do it in the most elegant way, since geometry is not my forte).

I kind of hope that I have something missing and that there is a way to pull out an object of automatically translated coordinates and sizes.

in an ideal world, I could call (pseudo) myImg.getDisplayedWidth() and myImg.getDisplayedX() .

Oh, and I have to add that this can be a problem that I cause myself, using the center of the image as a point from which to zoom in / out. If I left the default coordinate of 0.0 as a fixed point, I think the location will be correct, regardless of its size. So ... maybe the answer to all this is to simply calculate my center offset and apply it to my translations?

All help is much appreciated (and people don’t arbitrarily fight my question with a name even more!).

+4
source share
1 answer

The Matrix method mapPoints(float[] dst, float[] src) can be used to get a series of translated points using the Matrix translation. Or in (slightly) more unprofessional terms, an instance of the Matrix class contains not only a translation instruction, but also convenience methods for applying the Matrix transformation to a number of points.

So, in your case, you only need the corners of your untranslated bitmap (x, y, width, height) and pass the corner points to this method to get the translated points.

+2
source

Source: https://habr.com/ru/post/1381844/


All Articles