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

标签 iphone ios objective-c xcode crop

enter image description here

我只需要得到没有背景的选定图像,我们正在努力避免背景,我们只需要裁剪选定的部分。以及如何在点击选择图像颜色时更改像素数据。

或者我们可以这样做吗:

裁剪前:

enter image description here

裁剪后:

enter image description here

最佳答案

您可以允许用户在使用 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();

关于iphone - 如何避免从照片库中选择或从 ios 中的相机捕获的图像的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16100615/

相关文章:

Objective-C:如何读取 JSON?

ios - 使用一个与 UISwitch 相同的 UIButton

iphone - 一台特定 iOS 设备的新崩溃日志未出现在管理器中

ios - 使用 xib 创建自定义 MKAnnotationView

iphone - IframeExtractor 不使用 rtsp 输出声音

iphone - iPhone XCode 项目中的 C 二进制/源代码

ios - 对 Facebook 审核流程感到困惑

ios - 使用 URL 在 Xcode 中修改 UIImageview

ios - 向sqlite数据库中插入数据

objective-c - 如何从弱属性中移除 KVO?