簡體   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