使android中徒手裁剪的图像的部分变暗 [英] Darken parts of a free-hand cropped image in android

查看:105
本文介绍了使android中徒手裁剪的图像的部分变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加免提功能.

现在,借助以下代码,我可以打开图片并在要裁剪的图像部分周围绘制路径:

Till now I can open the picture and draw a path around the part of the image that I want to crop thanks to this code:

https://stackoverflow.com/a/18459072/2361533

但是在另一个活动中打开裁剪后的图像之前,我想使裁剪路径的外部变暗,以向用户展示裁剪后的图像.万一他不喜欢这个结果,他可以重置图像.

But before opening the cropped image in another activity, I want to darken the outside part of the crop path, to show the user how the cropped image will be. In case he does not like the result, he could reset the image.

就像下面的图片一样: Android:免费裁剪图片

It would be something like the image here: Android: Free Croping of Image

我该怎么做?

推荐答案

使用以下两种方法作为开始:

Use the following two methods as a start:

setXfermode(new PorterDuffXfermode(Mode.DARKEN)); 
canvas.clipPath(path, Region.Op.DIFFERENCE);

第一个应用于Paint对象,并使某个区域变暗. 第二个剪切"画布中的路径并取反(使用Region.Op.DIFFERENCE).

The first one is applied to a Paint object and darkens a certain region. The second "clips" the path in your canvas and takes the inverse (using Region.Op.DIFFERENCE).

这篇关于使android中徒手裁剪的图像的部分变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆