【发布时间】:2011-09-30 03:22:58
【问题描述】:
对于使用简单 (x,y) 坐标绘制的位图,
float _x = x - (bitmap.getWidth() / 2);
float _y = y - (bitmap.getHeight() / 2);
canvas.drawBitmap(bitmap, _x, _y, null);
我可以detect if the bitmap has been touched。
我正在用
在屏幕上绘制位图 dest = new Rect(0,0,0,0);
src = new Rect(0,0,0,0);
mSpriteHeight = (int) (sprite_pixel_height * mScale + 0.5f);
mSpriteWidth = (int) (sprite_pixel_width * mScale + 0.5f);
src.top = 0;
src.left = 0;
src.bottom = mSpriteHeight;
src.right = mSpriteWidth;
dest.top = (int) (_x * mScale);
dest.bottom = (int) ((_x + mSpriteHeight) * mScale);
dest.left = (int) (_y * mScale);
dest.right = (int) ((_y + mSpriteWidth) * mScale);
canvas.drawBitmap(bitmap, src, dest, null);
试图将 screen density 因为"This function ignores the density associated with the bitmap. ... so must already have the appropriate scaling factor applied."
我无法检测到对已翻译位图的触摸。我必须使用mScale 进行类似的翻译,但我迷路了。
有没有更好的方法来定义我原来的canvas.drawBitmap(bitmap, src, dest, null);中的src和dest?
有人知道这样做的例子吗?我似乎找不到合适的搜索词来找到这样的例子。
【问题讨论】:
标签: android bitmap touch-event