【发布时间】:2012-03-13 07:26:06
【问题描述】:
我在这个网站上搜索了如何来回旋转图像,并在这个网站上的其他帖子的帮助下想出了我自己的,它工作得很好,唯一的问题是现在我让它工作了所以它以我喜欢的方式来回旋转,我现在如何将它定位在屏幕上? 到目前为止的代码如下:
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);
}
通常使用 drawBitmap 我用它来定位我的图像,但是这个使用 src 和 dst 而不是矩形的大小,所以现在它工作得很好但是我如何将屏幕上的位置从 0,0 更改为 where我想要它去吗?
这部分或大部分取自这篇文章: Sprite Rotation in Android using Canvas.DrawBitmap. I am close, what am I doing wrong?
除了如何在屏幕上设置 x 和 y 位置之外,这给了我一切所需的一切,对此的任何帮助将不胜感激,我一直在绞尽脑汁试图找到一种方法这设置了 x 和 y 位置没有运气,它可能很简单。 提前致谢。
【问题讨论】:
标签: android rotation drawbitmap