本文介绍了在Android中对图片进行徒手裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在android中对图像进行徒手裁剪。我能够使用触摸在图像上绘制任意形状,并收集数组列表中路径上的所有点。但是我无法提取任意形状内的图像部分。
I am implementing the freehand cropping on the image in android. I am able to draw the arbitrary shape on the image using touch and collect all the points on the path in the array list. But I am not able to extract the part of image inside the arbitrary shape.
我搜索了很多内容,但找不到合适的答案。没有人有这样的可行示例。
I searched quite a lot but was not able to find the appropriate answer. Does any body have a working example of this.
编辑:我可以使用位图上的以下代码创建任意形状。
I am able to create a arbitrary shape using the below code on the bitmap.
@Override protected void onDraw(Canvas canvas) { canvas.drawBitmap(scaledBitmap, 0, 0,null); path.reset(); boolean firstTouchPoint = true; for (int i = 0; i < lastPath.size(); i += 2) { Point point = lastPath.get(i); if (firstTouchPoint) { firstTouchPoint = false; path.moveTo(point.fXPosition, point.fYPosition); } else if (i < lastPath.size() - 1) { Point next = lastPath.get(i + 1); path.quadTo(point.fXPosition, point.fYPosition, next.fXPosition, next.fYPosition); } else { path.lineTo(point.fXPosition, point.fYPosition); } } canvas.drawPath(path, paint); },但我无法提取
推荐答案您应该尝试以下操作:
//the image should support transparency. Bitmap scaledBitmap = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888); // fill the area around the path with alpha Canvas c = new Canvas(scaledBitmap); c.clipPath(path, Region.Op.DIFFERENCE); c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);更多推荐
在Android中对图片进行徒手裁剪
发布评论