How to scale to / from, rotate together in Android

I want to apply drag and drop, zoom in / out, rotate with multi-touch on two images .one image is placed on top of the other. after applying these steps

Create image

top two images after changes made through actions.

I managed to apply zoom / drag to the top image by creating a new image.

Main problem -

1. How to apply an action to two images, one image at a time?

2.How to switch to another image from the currently displayed image (which layout should I use)?

3.How can a user be able to rotate or enlarge an image using multi-touch?

What I miss, Sorry for the list - :)

+4
source share
1 answer

1) You need to save the conversion to Bitmap1 and apply it again to Bitmap2. for example, you can use a Matrix calculated using touch events to apply it to two bitmaps.

2) I'm not sure that you will do what you want. I understand: you have several images (which may consist of two images placed on top of the other) floating on the layout, and you want to select one of them to resize / rotate. To do this, you can simply use the ontouch event for ImageView.

3) Rotation + scaling using multi-touch is not easy in Android, you need to write a lot of code to make it work well. I suggest you use the existing library. I used this one and it worked like a charm: http://code.google.com/p/android-multitouch-controller/

In the presented example, you can see http://code.google.com/p/android-multitouch-controller/source/browse/trunk/demo/MTPhotoSortr/src/org/metalev/multitouch/photosortr/PhotoSortrView.java that you at any time you can find the new center, angle and scale factor updated images in mImages(i).getCenterX() , mImages(i).getAngle() , mImages(i).getScaleX() , ... Using these values, you You can replicate transformations (rotation, scaling, translation) to another bitmap.

+6
source

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


All Articles