Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android定位使用rect的drawBitmap_Android_Rotation_Drawbitmap - Fatal编程技术网

android定位使用rect的drawBitmap

android定位使用rect的drawBitmap,android,rotation,drawbitmap,Android,Rotation,Drawbitmap,我搜索了这个网站,找到了如何来回旋转图像的方法,并在这个网站上的其他帖子的帮助下找到了我自己的方法,效果很好,唯一的问题是现在我让它工作了,所以它以我喜欢的方式来回旋转,我现在该如何在屏幕上定位它呢? 以下是迄今为止的代码: private Bitmap ray; private int mRot = -33; private boolean goRight = true; void onRotDraw(Canvas canvas) { in

我搜索了这个网站,找到了如何来回旋转图像的方法,并在这个网站上的其他帖子的帮助下找到了我自己的方法,效果很好,唯一的问题是现在我让它工作了,所以它以我喜欢的方式来回旋转,我现在该如何在屏幕上定位它呢? 以下是迄今为止的代码:

 private Bitmap ray;
    private  int mRot = -33;
    private boolean goRight = true;

    void onRotDraw(Canvas canvas)
    {
        int width = ray.getWidth();
        int height = ray.getHeight();

        if (mRot > 30){
            goRight = false;
        }
        if (mRot < -30){
            goRight = true;
        }
        if (goRight){
            mRot += 1;
        }else
        {
            mRot -= 1;
        }
               canvas.rotate(mRot,width / 2,height / 2);
               this.Draw_Sprite(canvas, 0, mRot ); 

    }

    public void Draw_Sprite(Canvas c, int whatever, int rot) {  
        //rotating image back and forth
        int width = ray.getWidth();
        int height = ray.getHeight();
         Rect src = new Rect(width - width, height - height, width, height);
         Rect dst = new Rect(width - width, height - height,   width,  height); 
         c.drawBitmap(this.ray, src, dst, null);
    }
私有位图射线;
私人内特mRot=-33;
私有布尔goRight=true;
void onrottraw(画布)
{
int width=ray.getWidth();
int height=ray.getHeight();
如果(mRot>30){
戈赖特=假;
}
如果(mRot<-30){
戈赖特=真;
}
如果(戈赖特){
mRot+=1;
}否则
{
mRot-=1;
}
画布。旋转(mRot,宽度/2,高度/2);
绘制精灵(画布,0,mRot);
}
公共虚空绘制精灵(画布c,int任意,int rot){
//来回旋转图像
int width=ray.getWidth();
int height=ray.getHeight();
Rect src=新的Rect(宽度-宽度,高度-高度,宽度,高度);
Rect dst=新的Rect(宽度-宽度,高度-高度,宽度,高度);
c、 drawBitmap(this.ray、src、dst、null);
}
通常我使用drawBitmap来定位我的图像,但是这一个使用src和dst来代替矩形的大小,所以现在它工作得很好,但是如何将屏幕上的位置从0,0更改为我想要的位置呢

这部分内容或大部分内容摘自本帖:

除了如何在屏幕上设置x和y位置之外,这给了我所有我需要的东西,对此的任何帮助都将不胜感激,我一直在绞尽脑汁试图找到一种方法来设置x和y位置,但运气不好,这可能很简单。
提前感谢。

这是您引用的另一篇文章中的一段代码:

Rect src = new Rect(0, 0, width, height);
Rect dst = new Rect(x, y, x + width, y + height);
dst矩形中的x和y决定位图的位置

您的代码:

Rect src = new Rect(width - width, height - height, width, height);
Rect dst = new Rect(width - width, height - height,   width,  height);

总是将其绘制为0,0,因为宽度-宽度将为0,高度-高度将为0。

我太蠢了,好吧,我得到了那部分,感谢这一点,但现在我遇到了另一个问题,当我设置dst并将50添加到所有它现在不能正确旋转的东西上时,即使我给src和dst加上相同的数字,结果都是旋转不稳的(如果这是一个词的话),但是如果我把它们都像以前一样旋转得很好,这是一个缩放问题吗?我试过dst=newRect(50,50,50+宽度,50+高度)没关系,我是个笨蛋lol,我忘了把50添加到画布的其他部分。旋转(mRot,50+(宽度/2),50+(高度/2));现在一切都很好,谢谢你为我回答这个简单的问题,我感谢你花了这么多时间。