- FrameLayout(红色标注)
- 源 ImageView(黑色)
- 带有 OnTouchListener(橙色)的对象(图像视图)
通过带有 OnTouchListener 的对象,我想显示在 imageview(源 imageview)上填充的位图的一部分。
所以这不是问题,我正在这样做:
Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250);
其中:
- SourceBitmap - 是添加到源 ImageView 的图像
- event.getX() / event.getY()是一个坐标,我开始绘制位图的一部分
- 250 , 250 - 它是部分位图(部分)的大小。
结果是:
所以问题出现了,当我的对象(带有触摸监听器)进入边界时(我已经为橙色对象提供了这种可能性,使用 Object.width()/2 离开边界)。
所以在这种情况下:
我怎样才能达到这个结果:
部分的结果将是:
- 位图的一部分
- 第二部分是框架布局背景的颜色。
我目前尝试的方法:
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
//i want to draw bigger portion then corrds
int CurrentX = (int)view.getX() - (view.getWidth());
int CurrentY = (int)view.getY() - (view.getHeight());
//case,when object is going out of border
if(CurrentX <= 0)
{
Paint paint = new Paint();
paint.setStyle( Style.FILL );
paint.setColor( Color.RED );
mBitmap = Bitmap.CreateBitmap(sourceBitmap,(int)view.getX() + Math.abs(CurrentX),(int)view.getY(),250,250);
Canvas canvas = new Canvas(mBitmap);
canvas.drawBitmap(mBitmap,new Rect((int)view.getX()+Math.abs(CurrentX), (int)view.getY(),250-Math.abs(CurrentX),250),new RectF(Math.abs(CurrentX), 0, 250,250),paint);
}
break;
}
return true;
}
}
有什么建议么?谢谢!