Comments (3)
Hey,
This is actually a fairly complex task, even though it sounds simple. In order to zoom to a specific point on the image in an animation every "frame" of the animation has to do two things:
- Increase the scale by an amount proportional to the amount of time that has passed
- Move the center point of the image along a vector running on the OPPOSITE direction to the vector formed between the image center point and the touch point for a zoom.
The second part is the complicated bit. If you don't do this the image will "appear" to move outwards as it scales up because it always scales from the midpoint.
This is done in the pinch-zoom code here:
If you wanted to do this I would put all your logic into the ZoomAnimation object. That is, the touch point (x,y) and the length of time you want the animation to last.
The "elapsedTime" parameter in the update() method of the animation gives you the total elapsed time since the animation started. So the position and scale should be based on this time vs. the length of time you want the animation to last.
I do plan to implement this at some point, and whenever that is I would most likely do this:
When the ZoomAnimation is started record the midpoint of the image and the touch point for the destination, then calculate the vector between the two. (using the VectorF object).
Once you have this you adjust its length then use it to calculate the expected x,y position for the NEW midpoint of the image. The amount the midpoint should be moved is calculated from the initial distance between the original midpoint and the touch point together with the scale. For example.. if the touch point is calculated at a distance of 100 from the midpoint of the image, and you want to scale by 150% then the scaled distance is 150, this means you have to move the image by 50 in the OPPOSITE direction to the vector between the midpoint and the touch point.
Confused yet? ;)
from gesture-imageview.
thank you for the outline. I will give it a try. Do I need to change something outside ZoomAnimation?
for exmple on double tap return e.g.?
if(doubleTapDetector.onTouchEvent(event)) {
initialDistance = 0;
lastScale = currentScale;
//lastScale = image.getScale();;
currentScale = image.getScale();;
next.x = image.getImageX();
next.y = image.getImageY();
calculateBoundaries();
image.animationStart(new ZoomAnimation());
}
from gesture-imageview.
Actually.. I've already implemented this. Just not quite finished. Will upload soon
from gesture-imageview.
Related Issues (20)
- Gesturimageview scrolling issues HOT 1
- Unable to setImageBitmap from AsyncTask.onPostExecute method HOT 2
- Bitmap too large to be uploaded into a texture HOT 2
- setScale & setPosition problems HOT 2
- rotate the image
- Enable zoom only in center
- Doesn't support dynamic image setting! HOT 2
- Maintanenance of this utility
- Bad scale in landscape screen orientation HOT 1
- Display image from url HOT 2
- load from cloud HOT 6
- onLongClick not working in ViewPager. HOT 2
- can not use for next image
- please,add this library to maven/jcenter.thanks. HOT 3
- Bad XML block: header size 93 or total size 0 is larger than data size 0
- Support cropping of Bitmap in GestureImageView
- Solve gesture-imageview in viewpage can't Drag
- Not support the onSwipeTouchListener
- Hangs on ZoomIn and ZoomOut
- A possible fix for dynamic image loading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gesture-imageview.