Android的 - 围绕中心点旋转图像? [英] Android - Rotate image around center point?

查看:236
本文介绍了Android的 - 围绕中心点旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以旋转的位图(而不是视图或帆布)围绕其中心点当用户触摸并拖动它?

我曾尝试对堆栈溢出的例子负载,没有出现一起工作。

到目前为止,我有:

 双R = Math.atan2(POSX  -  dial.getWidth()/ 2,dial.getHeight()/ 2  - 波西);
旋转=(int)的Math.toDegrees(r)的;
 

解决方案

创建矩阵则设置为通过的 setRotate(度) 。然后使用创建新的位图时,这个矩阵:<一href="http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap%28android.graphics.Bitmap,%20int,%20int,%20int,%20int,%20android.graphics.Matrix,%20boolean%29"相对=nofollow> Bitmap.createBitmap(..)

How can I rotate a bitmap (not a view or canvas) around its center point when the user touches it and drags it?

I have tried loads of examples on stack overflow and none appear to work.

So far I have:

double r = Math.atan2(posX - dial.getWidth() / 2, dial.getHeight() / 2 - posY);
rotation = (int) Math.toDegrees(r);

解决方案

Create Matrix then set rotate via setRotate(degrees). Then use this matrix when creating new Bitmap: Bitmap.createBitmap(..)

这篇关于Android的 - 围绕中心点旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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