使用drawBitmap和矩形缩放位图 - Android
我正在开发一个小型图像编辑器。基本上,用户可以在画布中插入一些图像,并通过与手指的交互来移动它们。我在缩放时遇到一些问题。我遵循了这个的想法教程使用位图,并对两个矩形应用变换。之后,如果我们使用 android.graphics.Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint Paint) 在画布上绘制位图,则会应用转换。到目前为止,对我来说不起作用。
我将所有图像存储在图像数组 ColorBall
中。 时,并且只有当它位于某个图像上时(到目前为止这有效),我才会对该图像应用变换(这些值是虚拟的,只是想检查它是否有效):
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;
当我检测到有缩放手势 事件,对于数组中的所有图片,我找到它们,然后使用矩形缩放它们。到目前为止,缩放部分不起作用:
//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);
}
有什么建议我可以在这里错过什么吗?提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在添加到底部/右侧,因此您实际上只是将背景源移动到右侧十位,而不是缩放。
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.