android - onScale and Canvas - how to adjust origin point after zooming image? -
I have a very simple test app with a custom component - which shows a scrollable and scalable image (a board in Scrabble Represents the term of the game):
< P> 1) I adjust the scale factor in the listener of my scale:
Public Bullion on Scale (Scalgester Detector Detector) {mScale * = detector.getScaleFactor (); // XXX How to adjust mOffsetX and mOffsetY? XXX Blocking (); ConstrainOffsets (); Invalid (); Back true; }
2) And then in the drawing method of my custom component, I apply the translation and scale factor:
secure entry onda (canvas canvas) {Super.onDraw (canvas); Canvas.translate (mOffsetX, mOffsetY); Canvas.scale (mScale, mScale); Gamebird.Setbound (0, 0, GameBoardedIntertricic Wideth), gameBoard.getIntrinsicHeight ()); GameBoard.draw (canvas); }
Unfortunately, a small bug appears while scaling with a pinch gesture -
I can see, scale and limitations are the right size after zooming, But the image is not offset.
The problem gets worse, when the point of pinch point is far from 0, the 0 point of the screen.
This is one of the difficulties to describe the problem in words, but when you check out, you will see it immediately (and you can always tap and double offset to reset the scale ).
This is probably a common problem, it's the standard way to resolve it, but I'm still unable to find it.
is the image of the board and this code is based on the blog.
with You are going to the canvas twice:; translation
, then with scale (SX, SI, PX, PA): div class = "post-text" itemprop = "Text">
.
You can add your offset to your on scale
and then use scale (sx, sy)
.
Comments
Post a Comment