繁体   English   中英

Android编程位图旋转

[英]Android programming bitmap rotation

我试图使位图旋转并指向鼠标,但得到奇怪的结果:

视频: http//www.truploader.com/view/993341

鼠标不可见,但会旋转,但是不会旋转到鼠标的尖端。

码:

     /**
    * Rotates the object based on a point
    */
 public void setRotation(float x, float y)
 {
  float XDistance = this.xPos - x;
        float YDistance = this.yPos - y;

        float Radians =  (float) Math.atan2(YDistance, XDistance);
        this.degrees = Math.round((Radians*180/Math.PI));

       this.moveObject();
       this.r.setRotate(this.degrees, this.picture.getWidth() / 2, this.picture.getHeight());  //origin of the base
  // this.r.setRotate(this.degrees, this.picture.getWidth() / 2, this.picture.getHeight() / 2);  
 }

鼠标位置是x和y。 有任何想法吗?

您从哪里获得“鼠标位置”? 我猜您是从MotionEvent中获取的,因此请注意,此坐标是相对于目标View原点的。

您期望得到什么结果? Rotates the object based on a point可能意味着很多事情。 怎么了

学位正确吗? 初始化您的对象,伪造鼠标位置,然后查看this.degrees是否是您期望的以及您需要的对象。 如果不起作用,请考虑编写单元测试。

this.moveObject();是什么? 做? 它会做什么,应该做正确的事情吗?

this.r.setRotate(是否需要度?为什么this.picture.getWidth() / 2 ?关于它旋转哪一点?

那怎么了

暂无
暂无

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

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