I'm developing a small image editor. Basically, the user can insert some images in a canvas, and through interaction with the fingers moving them around. I'm having some trouble with the Zooming. I have followed the idea of this tutorial to use a bitmap, and to apply transformations to two rectangles. Afterwards, if we draw the bitmap over the canvas with android.graphics.Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
, the transformation is applied. So far, is not working for me.
I store all the images in an array of images, ColorBall
. When I detect there is a zoom gesture, and only if it was over a certain image (this works so far), I apply over that image the transformations (the values are dummy, just wanted to check if it works):
colorballs.get(balID-1).getmRectDst().left = getLeft();
colorballs.get(balID-1).getmRectDst().top = getTop();
colorballs.get(balID-1).getmRectDst().right = getRight();
colorballs.get(balID-1).getmRectDst().bottom = getBottom();
colorballs.get(balID-1).getmRectSrc().left += 10;
colorballs.get(balID-1).getmRectSrc().top += 10;
colorballs.get(balID-1).getmRectSrc().right += 10;
colorballs.get(balID-1).getmRectSrc().bottom += 10;
On the OnDraw event, for all the pictures in the array I locate them, and then I scale them using the rectangles. So far, the part of scaling is not working:
//draw the balls on the canvas
for (ColorBall ball : colorballs) {
canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), null);
canvas.drawBitmap(ball.getBitmap(), ball.getmRectSrc(), ball.getmRectDst(), mPaintBalls);
}
Any suggestion of what can I be missing here? Thanks in advance!
It looks like you are adding to the bottom/right, so instead of zooming you are actually just shifting the background source to the right ten.