简体   繁体   English

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

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

在此输入图像描述

I need to get only the selected image without background , we are trying to avoid the back ground and we need selected part should only cropped. 我只需要获得没有背景的选定图像,我们试图避开背景,我们需要选择的部分才能被裁剪。 and how to change the pixel data on tap selection of image color. 以及如何在图像颜色的选择上更改像素数据。

OR can we do like this: 或者我们可以这样做:

Before crop: 作物前:

在此输入图像描述

After crop: 作物后:

在此输入图像描述

You can allow user to draw on image after selection using bezierpath, once you have path - You can use a shapeLayer for that. 您可以允许用户在选择后使用bezierpath绘制图像,一旦有了路径 - 您可以使用shapeLayer。 Something like: 就像是:

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

To get it as an image, 要将其作为图像,

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