如何设置drawBitmap不全屏
我有一个位图,我这样画它:
bit = BitmapFactory.decodeResource(getResources(),
R.drawable.anim_ctrl_panel);
Paint paint = new Paint();
canvas.drawBitmap(bit, 80, 440, paint);
问题是图像设置为全屏。在 onTouchEvent 方法上,我实现了位图的事件,并且在我选择屏幕的任何地方都实现了该事件。我希望图像具有一定的位置,并且只有该位置才能实现事件。我该怎么做?
编辑:问题出在 onTouchEvent 方法上。这就是解决方案:
public boolean onTouchEvent(MotionEvent event) {if(80 <= event.getX() && event.getX()<= (80+bit.getWidth()/2) && (440 <= event.getY() && (event.getY() <= 440+bit.getHeight()))){
//...
}else if((80+bit.getWidth()/2) <= event.getX() && event.getX()<= (80+bit.getWidth()) && (440 <= event.getY() && (event.getY() <= 440+bit.getHeight()))){
//...
}
这对我有帮助:我该怎么办使用 OnTouch() 检查图像是否被触摸
I have a bitmap and I draw it like this :
bit = BitmapFactory.decodeResource(getResources(),
R.drawable.anim_ctrl_panel);
Paint paint = new Paint();
canvas.drawBitmap(bit, 80, 440, paint);
The problem is that the image is set as fullscreen .On onTouchEvent
method I implement the event for the bitmap and anywhere I select screen the event is implement. I want the image to have a certain position and only for that position to be implement the event. How can I do this?
EDIT: the problem was at onTouchEvent method. This is the solution :
public boolean onTouchEvent(MotionEvent event) {if(80 <= event.getX() && event.getX()<= (80+bit.getWidth()/2) && (440 <= event.getY() && (event.getY() <= 440+bit.getHeight()))){
//...
}else if((80+bit.getWidth()/2) <= event.getX() && event.getX()<= (80+bit.getWidth()) && (440 <= event.getY() && (event.getY() <= 440+bit.getHeight()))){
//...
}
this help me : How can I check the Image is Touched using OnTouch()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于特定区域的图像集,我认为矩形对此很有用,
类似这样的东西(在我的情况下它对我有用)
尝试一下。
有关详细信息,请参阅 Android - 绘图(核心)
谢谢。
For Image set in particular area, I think Rectangle is useful for this,
Something like this, (In my case Its work for me)
Try it.
For more info look at Android - Drawing (Core)
Thanks.
试试这个:
Try this: