简体   繁体   English

通过触摸并拖动图像直到要旋转的点来旋转图像

[英]Rotating an image around a point by touching and dragging it till the point we want to rotate it

Actually what I want to do is I have a Bitmap image I'm using SurfaceView instead of View to draw and using onDraw function to draw the image. 实际上我想要做的是有一个位图图像,我使用SurfaceView而不是View进行绘制,并使用onDraw函数绘制图像。

What I want to do is I have an image a pointer with arrow (like a needle we have in multimeter) I want the user to touch the tip of the arrow and rotate if by holding n dragging till the point he wants to rotate it to. 我想做的是我有一个带有箭头的指针的图像(就像万用表中的针一样)。我希望用户触摸箭头的尖端并旋转,如果按住n拖动直到他想要旋转到该点。 ie if arrow is straight then 90 degree on either side we can rotate. 即,如果箭头是笔直的,那么任一侧的角度均为90度,我们就可以旋转。

I found few examples on this site and internet but non of them were precise or explained anything and were hard to understand. 我在本网站和互联网上发现的例子很少,但没有一个是精确的或没有任何解释,很难理解。

If someone can help me with this I would be very grateful. 如果有人可以帮助我,我将非常感激。

You have two things to do. 您有两件事要做。 Detect the touch and then rotate the image. 检测触摸,然后旋转图像。

For the touch stuff you need to use an onTouchListener there are plenty of questions about draging which is the same basic code try this one 对于需要使用onTouchListener的触摸式东西,有很多有关拖动的问题,这与基本代码相同,请尝试

Somthing that may help with the rotate here You basicaly use a Matrix and use it to transform a bitmap . 可能对此处旋转有所帮助的东西基本上,您可以使用Matrix并将其用于转换位图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM