I want to create cropping bitmap functionality and called Android: Free Croping of Image , but this sets the bitmap to another image. Now I know that I can set the cropped bitmap in the canvas, but I want to save the original bitmap and want to crop in onDraw (), and not create another bitmap and then set it to canvas. I tried to implement the code below in onDraw, but no cropping and bitmap remains as they are. Help so that I can code this in the onDraw () method of CustomView.
compositeImageView = (ImageView) findViewById(R.id.our_imageview); Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.gallery_12); Bitmap resultingImage = Bitmap.createBitmap(widthOfscreen, heightOfScreen, bitmap2.getConfig()); Canvas canvas = new Canvas(resultingImage); Paint paint = new Paint(); paint.setAntiAlias(true); Path path = new Path(); for (int i = 0; i < SomeView.points.size(); i++) { path.lineTo(SomeView.points.get(i).x, SomeView.points.get(i).y); } canvas.drawPath(path, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap2, 0, 0, paint); compositeImageView.setImageBitmap(resultingImage);
my onDraw () method
@Override protected void onDraw(Canvas canvas) { Bitmap bitmap1 = bitmap.copy(bitmap.getConfig(), true); canvas.drawBitmap(bitmap1, 0,0, null); Paint paint = new Paint(); paint.setAntiAlias(true); Path path = new Path(); for (int i = 0; i < SomeView.points.size(); i++) { path.lineTo(SomeView.points.get(i).x, SomeView.points.get(i).y); } canvas.drawPath(path, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap,0, 0, paint); }
zek54 source share