简体   繁体   中英

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. 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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