我有一个
: @H_301_3@> FrameLayout(标记为红色)
> Source ImageView(黑色)
> Object(imageview)与OnTouchListener(橙色) @H_301_3@Via Object with OnTouchListener,我想显示位图的一部分,它们填充在imageview(源imageview)上. @H_301_3@所以这不是一个问题,我这样做:
Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250); @H_301_3@哪里: @H_301_3@> SourceBitmap – 是添加到ImageView的图像
> event.getX()/ event.getY()是一个坐标,我开始绘制位图的一部分
> 250,250 – 其大小的部分位图(部分). @H_301_3@结果是: @H_301_3@ @H_301_3@所以问题出现了,当我的对象(用touchlistener)进入边界(我已经使这个橙色对象的可能性,与Object.width()/ 2)离开界限. @H_301_3@所以在这种情况下
我如何实现这个结果:
部分结果为: @H_301_3@>位图的一部分
>第二部分是framelayout背景的颜色. @H_301_3@我在当下时刻尝试过的
: @H_301_3@> FrameLayout(标记为红色)
> Source ImageView(黑色)
> Object(imageview)与OnTouchListener(橙色) @H_301_3@Via Object with OnTouchListener,我想显示位图的一部分,它们填充在imageview(源imageview)上. @H_301_3@所以这不是一个问题,我这样做:
Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250); @H_301_3@哪里: @H_301_3@> SourceBitmap – 是添加到ImageView的图像
> event.getX()/ event.getY()是一个坐标,我开始绘制位图的一部分
> 250,250 – 其大小的部分位图(部分). @H_301_3@结果是: @H_301_3@ @H_301_3@所以问题出现了,当我的对象(用touchlistener)进入边界(我已经使这个橙色对象的可能性,与Object.width()/ 2)离开界限. @H_301_3@所以在这种情况下
我如何实现这个结果:
部分结果为: @H_301_3@>位图的一部分
>第二部分是framelayout背景的颜色. @H_301_3@我在当下时刻尝试过的
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); Canvas canvas = new Canvas(mBitmap); canvas.drawBitmap(mBitmap,new Rect((int)view.getX()+Math.abs(CurrentX),250-Math.abs(CurrentX),250),new RectF(Math.abs(CurrentX),paint); } break; } return true; } }@H_301_3@有什么建议么?谢谢!
解决方法
自己解决!
这很复杂,但结果相当不错.
开始了:
所以对于我的情况(当OnTouchListener的对象可以离开X和Y轴上的边框时),我已经做了Post Conditions(某种规定). @H_301_3@条件 @H_301_3@Width = imageView的宽度,我想显示结果.
Height = imageView的高度,我想显示结果; @H_301_3@左边 @H_301_3@> X_Coord< 0&& Y_Coord - 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord< 0&& Y_Coord - Height / 2> 0&& Y_Coord< Bitmap.Height
这是我们的中间区.
> X_Coord< 0&& Y_Coord - Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层. @H_301_3@右边 @H_301_3@> X_Coord> Bitmap.Height&& Y_Coord – Height / 2> 0&& Y_Coord Bitmap.Height
这是我们的中间区.
> X_Coord> Bitmap.Height&& Y_Coord – 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord> Bitmap.Height&& Y_Coord – Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层. @H_301_3@Standart(中间区域,不会左侧或右侧) @H_301_3@> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层.
> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - Height / 2> 0&& Y_Coord< Bitmap.Height
这是我们的中间区. @H_301_3@所以通过这个“条件”,我在我的MotionEvent.ACTION_MOVE情况下绘制位图的一部分.
我们来看一些例子:
这很复杂,但结果相当不错.
开始了:
所以对于我的情况(当OnTouchListener的对象可以离开X和Y轴上的边框时),我已经做了Post Conditions(某种规定). @H_301_3@条件 @H_301_3@Width = imageView的宽度,我想显示结果.
Height = imageView的高度,我想显示结果; @H_301_3@左边 @H_301_3@> X_Coord< 0&& Y_Coord - 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord< 0&& Y_Coord - Height / 2> 0&& Y_Coord< Bitmap.Height
这是我们的中间区.
> X_Coord< 0&& Y_Coord - Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层. @H_301_3@右边 @H_301_3@> X_Coord> Bitmap.Height&& Y_Coord – Height / 2> 0&& Y_Coord Bitmap.Height
这是我们的中间区.
> X_Coord> Bitmap.Height&& Y_Coord – 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord> Bitmap.Height&& Y_Coord – Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层. @H_301_3@Standart(中间区域,不会左侧或右侧) @H_301_3@> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - 高度/ 2 < 0&& Y_Coord< Bitmap.Height
这是我们的顶级区域.
> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - Height / 2> 0&& Y_Coord> Bitmap.Height
这是我们的底层.
> X_Coord – Width / 2> 0&& X_Coord< Bitmap.Width&& Y_Coord - Height / 2> 0&& Y_Coord< Bitmap.Height
这是我们的中间区. @H_301_3@所以通过这个“条件”,我在我的MotionEvent.ACTION_MOVE情况下绘制位图的一部分.
我们来看一些例子:
public boolean onTouch(View view,MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: int Width = ResultImgView.getWidth(); int Height = ResultImgView.getHeight(); //paint for our Red background Paint paint = new Paint(); paint.setStyle( Style.FILL ); paint.setColor( Color.RED ); Bitmap mBitmap = null; Canvas canvas = null; //Our Condition if(view.getX() - Width / 2 >= SourceBitmap.getWidth() && view.getY() - Height / 2 > 0 && view.getY() + Height / 2 < SourceBitmap.getHeight()) { //Nice,we entered here. Seems that we're now located at RightSide at Middle position //So let's draw part of bitmap. //our margin for X coords int Difference = (int)((view.getX() - Width / 2 ) - SourceBitmap.getWidth(); //dont forget to put margin //BTW we're now took portion of bitmap mBitmap = Bitmap.createBitmap(SourceBitmap,((int)view.getX() - Width / 2) - Difference,(int)view.getY() - Height / 2,Width,Height); canvas = new Canvas(mBitmap); //draw rect canvas.drawRect(0,mBitmap.getWidth(),mBitmap.getHeight(),paint); //draw portion of bitmap canvas.drawBitmap(mBitmap,new Rect(Difference,mBitmap.getHeight()),new Rect(0,mBitmap.getWidth() - Difference,null); //and that's all! } //do the same for other condition....etc break; } return true; }@H_301_3@请享用! @H_301_3@PS对不起我的eng