在Android中对图片进行徒手裁剪

编程入门 行业动态 更新时间:2024-10-28 09:20:15
本文介绍了在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中对图片进行徒手裁剪

本文发布于:2023-08-02 03:42:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274326.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中对   图片   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!