我有一个
:
1.框架布局(标记为红色)
1.源图像视图(黑色)
1.具有OnTouchListener(橙子)的对象(图像视图)
通过带有OnTouchListener的Object,我想显示在imageview(源imageview)上填充的位图的一部分。
所以这不是一个问题,我这样做:Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250);
所在地:
1.SourceBitmap-是添加到源ImageView的图像
1.event.getX()/**event.getY()**是一个坐标,我从这里开始绘制位图的一部分
1.250,250-其大小为部分位图(part)。
结果为:
因此,当我的对象(使用touchlistener)进入边界时,问题就出现了(我已经为橙子对象设置了这种可能性,使用Object.width()/2将其移出边界)。
因此在本例中:
我怎样才能达到这个结果:
其中部分结果将是:
1.部分位图
1.第二部分是框架布局背景颜色。
我目前尝试的是:
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;
}
}
有什么建议吗?谢谢!
2条答案
按热度按时间dy1byipe1#
Solved by myself!
It was complicated,but result is pretty nice.
Here we go:
So for my case(when object with OnTouchListener can go out of border On X and Y axes),i've made Post Conditions(some kind of regulations).
Conditions
Width = Width of imageView,where i want to show result.
Height = Height of imageView,where i want to show result;
LeftSide
This is our Top Area.
This is our Middle Area.
This is our Bottom Area.
RightSide
This is our Middle Area.
This is our Top Area.
This is our Bottom Area.
Standart(Area of Middle,that are not going to Left or Right side)
This is our Top Area.
This is our Bottom Area.
This is our Middle Area.
So via this "Conditions",i'm drawing portion of bitmap on my
MotionEvent.ACTION_MOVE
case.Let's see some example:
Enjoy!
wpx232ag2#
如果
sourceBitmap
只是ImageView
中的位图集,那么结果是可以预测的。要实现您的目标,您需要:FrameLayout
坐标中的橙子正方形坐标。看起来你已经有了正确的坐标。1.作为
sourceBitmap
,你必须使用FrameLayout.draw
方法创建的Bitmap
。注意你的橙子正方形必须不是FrameLayout's
子对象。如果你把你所有的代码贴在某个地方,我可以检查它。