11
두 개의 둥근 모서리 만 제공 할 수 있도록 이미지를 마스크하려고합니다. 코드를 사용하면 마스크를 이미지 위에 흰색으로 추가하지만 적용하지 않는 것입니다. 이미지 모서리를 가려면 어떻게해야합니까? 위의 링크 된 질문에서 언급 한 바와 같이iOS : UIBezierPath를 사용하여 UIImage를 마스크하십시오.
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(16.f, 16.f)];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [roundedPath CGPath];
// Add mask
self.imageView.layer.mask = maskLayer;
darvidsOn은 내가 UIImage에서 마스크 된 이미지를 저장할 수있는 방법을 말해 줄 수 있습니까? ??? –
Apple의 설명서를 읽으십시오. [UIImage'] (http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html)와 [CGImage'] (http : //developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGImage/Reference/reference.html#//apple_ref/doc/uid/TP30000956-Reference-DontLinkElementID_1), 이는 내부 이미지 객체 인' UIImage'. CGImage에는 마스크를 사용하여 이미지를 생성하는 함수가 있고 새로운'CGImage'를 이미지로 가져 오는 UIImage 생성자가 있습니다. – darvids0n
답장을 보내 주셔서 감사합니다. 내가 묻는 이유가 무엇인지 찾을 수 없습니다 ... –