放大使用canvas.scale功能的印刷品吗? [英] Zoom in a canvas using canvas.scale function?
问题描述
我已经实现了它绘制一组矩形长的OnDraw方法。矩形太小,我希望他们能够出现较大。但遗憾的是我不能改变的矩形坐标becoz它们存储在数据库中。那么,有什么办法可以在画布上用canvas.scale(缩小)?
I have implemented a long Ondraw method which draws a set of rectangles. the rectangles are too small and i want them to appear bigger. But unfortunately i cant change the rectangle coordinates becoz they are stored in a database. So is there any way i can Zoom in the canvas using the canvas.scale() ?
推荐答案
我说,你将需要绘制的一切,在0,0,然后扩展它,最后它翻译成去preface这个答案表现正常。
I'm going to preface this answer by saying you will need to draw everything at 0,0 and then scale it, and finally translate it to behave properly.
根本就在你的OnDraw方法如下:
Simply do the following in your onDraw method:
canvas.save();
canvas.translate(xValue, yValue);
canvas.scale(xScale, yScale)
/* draw whatever you want scaled at 0,0*/
canvas.restore();
xScale等收缩或伸展在X方向, yScale收缩或伸展在Y方向。
xScale shrinks or stretches in the X direction, yScale shrinks or stretches in the Y direction.
1.0是默认了这些,所以2.0可以拓展它采用双和0.5将减半缩水了。
1.0 is the default for these, so 2.0 would stretch it by double and 0.5 would shrink it by half.
例如:
canvas.save();
canvas.translate(50, 50);
canvas.scale(0.5f, 0.5f);
canvas.drawRect(0.0, 0.0, 5.0, 5.0, paint);
canvas.restore();
这将吸引长度5.0一个矩形,宽5.0,比例缩小到2.5的长度和宽度,然后将其移动到(50,50)。
This will draw a rectangle with length 5.0, and width 5.0, scale it down to 2.5 for length and width, and then move it to (50, 50).
结果将是,如果你这样做矩形得出:
The result will be a rectangle drawn as if you did this:
canvas.drawRect(50.0, 50.0, 52.5, 52.5, paint);
我希望这有助于!
I hope this helps!
这篇关于放大使用canvas.scale功能的印刷品吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!