public void hatdraw(Canvas canvas,float x,float y) {
mBitmaps = BitmapFactory.decodeResource(this.getResources(),
R.drawable.hat);
srcRect=new Rect(0,0,60,60);
xrect=(int)x;
yrect=(int)y;
Log.d("hatdraw","xrect,yrect"+xrect +yrect);
desRect=new Rect(xrect,yrect, xrect+ (srcRect.right - srcRect.left),
yrect + (srcRect.bottom -srcRect.top));
canvas.drawBitmap(mBitmaps,srcRect,desRect, null);
}
答案 0 :(得分:3)
我不知道发布的代码与此问题的标题有什么关系,但请查看Rect.contains(int x, int y)
(或RectF
中的等效方法)进行该测试。
答案 1 :(得分:0)
触摸位图...
if (x >= xOfYourBitmap && x < (xOfYourBitmap + yourBitmap.getWidth())
&& y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight()))
{
// if this is true, you've started your click inside your bitmap
}