繁体   English   中英

如何避免从照片库中选择或从ios中的相机中捕获的图像的背景?

[英]how to avoid background for an image which is selected from photo gallery or captured from Camera in ios?

在此输入图像描述

我只需要获得没有背景的选定图像,我们试图避开背景,我们需要选择的部分才能被裁剪。 以及如何在图像颜色的选择上更改像素数据。

或者我们可以这样做:

作物前:

在此输入图像描述

作物后:

在此输入图像描述

您可以允许用户在选择后使用bezierpath绘制图像,一旦有了路径 - 您可以使用shapeLayer。 就像是:

CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 

shapeLayer.path = aPath.CGPath;

[view.layer setMask:shapeLayer];//or make it as

[imageview.layer setMask:shapreLayer]; 

// and add imageView as subview  of whichever view you want. 
// draw the original image on the imageview in that case

要将其作为图像,

UIGraphicsBeginImageContext(view.bounds.size);
[view.layerrenderInContext:UIGraphicsGetCurrentContext()]; 

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM