问题描述
我需要裁剪位图,但不是在一个矩形裁剪图像(这是我成功设法做到),我需要它是任何形式的按定义的坐标。
我下面从这个线程的答案:Cutting多点ploygon出位图,并把它放在透明,并试图实现它,但不幸的是它不裁剪图像。
我一样的描述,但似乎有一个错误的地方。所述绘制图像中的矩形的方法。我失去了一些东西?
位图originalBitmap = BitmapFactory.de codeResource(getResources(),R.drawable.test_image);
//图像裁剪
位图croppedBitmap = Bitmap.createBitmap(originalBitmap,10,10,200,200);
帆布油画=新的Canvas(croppedBitmap);
//创建一个路径
路径path =新路径();
path.setFillType(FillType.INVERSE_EVEN_ODD);
path.moveTo(0,0);
path.moveTo(0,100);
path.moveTo(100,0);
path.moveTo(0,0);
//与Xfermode涂料
涂料粉刷=新的油漆();
paint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.CLEAR));
//绘制路径
canvas.drawPath(路径,油漆);
imageView.setImageBitmap(croppedBitmap);
我是非常接近的解决方案。在这里,它是:
compositeImageView =(ImageView的)findViewById(R.id.imageView);
位图bitmap1 = BitmapFactory.de codeResource(getResources(),R.drawable.batman_ad);
位图bitmap2 = BitmapFactory.de codeResource(getResources(),R.drawable.logo);
位图resultingImage = Bitmap.createBitmap(320,480,bitmap1.getConfig());
帆布油画=新的Canvas(resultingImage);
涂料粉刷=新的油漆();
paint.setAntiAlias(真正的);
路径path =新路径();
path.lineTo(150,0);
path.lineTo(230,120);
path.lineTo(70,120);
path.lineTo(150,0);
canvas.drawPath(路径,油漆);
paint.setXfermode(新PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap2,0,0,油漆);
compositeImageView.setImageBitmap(resultingImage);
I need to crop a Bitmap, but instead of having a rectangular cropped image (which I managed successfully to do), I need it to be any form defined by coordinates.
I'm following the answer from this thread: Cutting a multipoint ploygon out of Bitmap and placing it on transparency , and trying to implement it, but unfortunatly it does not clip the image.
I did as in the description, but it seems there's a bug somewhere. The image is drawn in rectangular way.Am I missing something?
Bitmap originalBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
// Image cropped
Bitmap croppedBitmap=Bitmap.createBitmap(originalBitmap, 10, 10, 200, 200);
Canvas canvas=new Canvas(croppedBitmap);
// Create a path
Path path=new Path();
path.setFillType(FillType.INVERSE_EVEN_ODD);
path.moveTo(0, 0);
path.moveTo(0, 100);
path.moveTo(100, 0);
path.moveTo(0, 0);
// Paint with Xfermode
Paint paint=new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
// Draw the path
canvas.drawPath(path, paint);
imageView.setImageBitmap(croppedBitmap);
I was very close to the solution. Here it is:
compositeImageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap1=BitmapFactory.decodeResource(getResources(), R.drawable.batman_ad);
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(), R.drawable.logo);
Bitmap resultingImage=Bitmap.createBitmap(320, 480, bitmap1.getConfig());
Canvas canvas = new Canvas(resultingImage);
Paint paint = new Paint();
paint.setAntiAlias(true);
Path path=new Path();
path.lineTo(150, 0);
path.lineTo(230, 120);
path.lineTo(70, 120);
path.lineTo(150, 0);
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap2, 0, 0, paint);
compositeImageView.setImageBitmap(resultingImage);
这篇关于Android的 - 裁剪从多点的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!