我試圖讓圖像的角落變圓,但來自ImageContext的圖像變形。ImageContext返回圖像失真
這是我採取的步驟:
- (UIImage *)decodeBase64ToImage:(NSString *)strEncodedData
{
NSURL *url = [NSURL URLWithString:strEncodedData];
NSData* data = [[NSData alloc] initWithContentsOfURL:url];
UIImage* image = [[UIImage alloc] initWithData:data];
UIImage* croppedImage = [self makeRoundedImage:image];
return croppedImage;
}
- (UIImage *)makeRoundedImage:(UIImage *) image
{
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext(frame.size);
//[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, image.size.width, image.size.height) cornerRadius:10.0] addClip];
[image drawInRect:frame];
// Get the image
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
// Lets forget about that we were drawing
UIGraphicsEndImageContext();
return croppedImage;
}
我覺得沒有必要讓UIImage的角落。你需要製作UIImageView的角落。 –
@YogendraGirase我不能使用UIImageView,我需要在只與UIImage一起工作的框架中使用它。 –
您可以在下面檢查我的答案。它可能對您有所幫助 –