使用drawBitmap和矩形缩放位图 - Android [英] Zoom a bitmap with drawBitmap and rectangles - Android

查看:380
本文介绍了使用drawBitmap和矩形缩放位图 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型图像编辑器。基本上,用户可以在画布中插入一些图像,并通过与移动它们的手指的交互。我在缩放方面遇到了一些麻烦。我遵循了这个的想法教程使用位图,并将转换应用于两个矩形。之后,如果我们使用 android.graphics.Canvas.drawBitmap(位图位图,Rect src,Rect dst,Paint paint)在画布上绘制位图,则应用转换。到目前为止,对我来说不起作用。

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.

我将所有图像存储在一个图像数组中, ColorBall 。当我检测到有缩放手势时,并且只有当它超过某个图像时(这个工作到目前为止),我在该图像上应用了转换(值是虚拟的,只是想检查它是否有效):

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;

在OnDraw事件中,对于数组中的所有图片,我找到它们,然后我缩放它们使用矩形。到目前为止,缩放的部分不起作用:

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.

colorballs.get(balID-1).getmRectSrc().right  -= 10;
colorballs.get(balID-1).getmRectSrc().bottom -= 10;

这篇关于使用drawBitmap和矩形缩放位图 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆