旋转图像围绕另一个图像的中心 [英] rotate image around a center of another image

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

问题描述

我已旋转拨号绕其中心与从以下连结的helop:

http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/

现在我有拨号器旁边的图标,我需要旋转它周围的拨号器,以及在一个圆形轨迹拨号器。

 私人无效rotateLogo(浮度){
                 矩阵nMatrix =新的Matrix();
                 位图peopleOrg = BitmapFactory.de codeResource(getResources(),R.drawable.peoplelogo);
                 浮translateX = dialerWidth / 2  -  dialerWidth / 2;
                 浮translateY = dialerHeight / 2  -  dialerWidth / 2;
                 nMatrix preTranslate(-turntable.getWidth()/ 2,-turntable.getHeight()/ 2)。
                 nMatrix.postRotate(度,translateX,translateY);
                 nMatrix.postTranslate(turntable.getWidth()/ 2,turntable.getHeight()/ 2);
                 位图peopleScale = Bitmap.createBitmap(peopleOrg,0,0,peopleOrg.getWidth(),peopleOrg.getHeight(),nMatrix,真);
                 peopleLogo.setImageBitmap(peopleScale);
                 peopleLogo.setImageMatrix(nMatrix);
    }
 

这只是使图像围绕其自己的中心,而不是围绕着拨号器的中心点旋转。 我不能找出我错了:(

更新

  1. 基本上,我需要的标志移动在一个圆形的道路,成为一个可点击查看。
  2. 在使用rotateAnim尝试,但认为犯规动画和我有麻烦的onclick事件。
  3. 在想任何帮助,可以旋转矩阵使用相同的
解决方案

只是试着用 peopleOrg 旋转,宽度和高度。

  nMatrix.postRotate(度,peopleOrg.getWidth()/ 2,peopleOrg.getHeight()/ 2);
 

更新:

现在你让我知道您的标志应该是一个可点击的视图,合并与您的拨号的标志形象是不适用的。要绕拨号器的中心标志来看,你应该实际计算(前左)点为您的标志图,移动它,不仅仅是旋转它。

使用正弦余弦函数来获取点上绘制的假想圆的圆周您的标志看法。

这篇文章将帮助你算了一笔账:<一href="http://stackoverflow.com/questions/839899/how-do-i-calculate-a-point-on-a-circles-circumference">How我计算的圆周长一点?

I have rotated a dial around its center with the helop from the link below:

http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/

Now I have an icon beside the dialer and I need to rotate it around the dialer, along with the dialer in a circular path.

    private void rotateLogo(float degrees){
                 Matrix nMatrix = new Matrix();
                 Bitmap peopleOrg = BitmapFactory.decodeResource(getResources(), R.drawable.peoplelogo);
                 float translateX = dialerWidth / 2 - dialerWidth / 2;
                 float translateY = dialerHeight / 2 - dialerWidth / 2;
                 nMatrix.preTranslate(-turntable.getWidth()/2, -turntable.getHeight()/2);
                 nMatrix.postRotate(degrees, translateX, translateY);
                 nMatrix.postTranslate(turntable.getWidth()/2, turntable.getHeight()/2); 
                 Bitmap peopleScale = Bitmap.createBitmap(peopleOrg, 0, 0, peopleOrg.getWidth(), peopleOrg.getHeight(), nMatrix, true);
                 peopleLogo.setImageBitmap(peopleScale);        
                 peopleLogo.setImageMatrix(nMatrix);                  
    }

This just causes the image to rotate around its own center and not around the dialer's center point. I cant find out where i am wrong :(

Updates

  1. I basically need the logo to move in a circular path and be a clickable view.
  2. Tried using rotateAnim but the view doesnt animate and i have trouble getting the onclick event.
  3. Would like any help that can rotate the same using matrices

解决方案

Try only rotate with peopleOrg width and height.

nMatrix.postRotate(degrees, peopleOrg.getWidth()/2, peopleOrg.getHeight()/2);

Update :

Now that you let me know that your logo should be a clickable view, merging the logo image with your dialer is not applicable. To rotate the logo view around the center of dialer you should be actually calculating the (top,left) point for your logo view and moving it around, than just rotating it.

Use sine and cosine functions to get the point on the circumference of an imaginary circle for drawing your logo view.

This post will help you with calculations : How do I calculate a point on a circle’s circumference?

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

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