我已生成使用掩模的圓的UIImage如下(其中masked_circle是一個黑圈):添加白色邊框沿着圓圈的UIImage
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
UIImage *maskImage = [UIImage imageNamed:@"masked_circle.png"];
CGImageRef maskImageRef = [maskImage CGImage];
// create a bitmap graphics context the size of the image
CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
CGFloat ratio = 0;
ratio = maskImage.size.width/ self.image_.size.width;
if(ratio * self.image_.size.height < maskImage.size.height) {
ratio = maskImage.size.height/ self.image_.size.height;
}
CGRect rect1 = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
CGRect rect2 = {{-((self.image_.size.width*ratio)-maskImage.size.width)/2 , -((self.image_.size.height*ratio)-maskImage.size.height)/2}, {self.image_.size.width*ratio, self.image_.size.height*ratio}};
CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
CGContextDrawImage(mainViewContentContext, rect2, self.image_.CGImage);
CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);
UIImage *theImage = [UIImage imageWithCGImage:newImage];
現在,在這之後,我想周圍添加1px的白色邊框圓形圖像,我該怎麼辦?
UIImage會在UIImageView中,或者你想要在UIImage中繪製實際的邊框嗎? – Eric
想要在UIImage本身中繪製實際的邊框 – adit