Hello everyone, there is the following:
:
- FrameLayout (displayed in red)
- Original ImageView (black)
- A quadview object (imageview) with a bolted OnTouchListener (orange), it is created inside FrameLayout.
Through the Object with OnTouchListener "th, I want to show the" part "of Bitmap, which is installed in the original ImageView.
In general, I do something like this:Bitmap bt = Bitmap.createBitmap(sourceBitmap,event.getX(),event.getY(),250,250);
where :
- SourceBitmap - image that is set to the original imageview
- event.getX () / event.getY () coordinates (a quadric object) from which I start to draw Bitmap's “ part ”.
- 250 , 250 - the size of the "piece" Bitmap.
and the result:
In general, a problem appears when an object (with the OnTouchListener screwed in), goes beyond the boundary of the original ImageView (there is such an opportunity, that is, half the length, can go abroad).
Those. in this case :
I expect this result:
more specifically:
- Part of bitmap.
- The second part is the " emptiness ", I mean the color of the Framelayout (background).
What I tried at the moment:
public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: //я хочу получить большую порцию,чем текущие координаты int CurrentX = (int)view.getX() - (view.getWidth()); int CurrentY = (int)view.getY() - (view.getHeight()); //случай когда изображение ушло за границы 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; } } And the problem is that the result is not what I expect.
And just as you can get the "result" (rectangle), without the original image, because because of the canvas.drawBitmap, the result is drawn over the original image.
