自己解决!
这很复杂,但结果相当不错.
开始了:
所以对于我的情况(当OnTouchListener的对象可以离开X和Y轴上的边框时),我已经做了Post Conditions(某种规定).
条件
Width = imageView的宽度,我想显示结果.
Height = imageView的高度,我想显示结果;
左边
> 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
这是我们的底层.
右边
> 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
这是我们的底层.
Standart(中间区域,不会左侧或右侧)
> 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
这是我们的中间区.
所以通过这个“条件”,我在我的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;
}
请享用!
PS对不起我的eng
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!