我已經能夠成功地重新繪製具有邊框的UIImage,但沒有邊框+陰影。下面的代碼成功地繪製了一個白色邊框的圖像,但我無法弄清楚如何在邊框下包含陰影。非常感謝幫助!在UIImage上繪製邊框和陰影
- (UIImage *)generatePhotoFrameWithImage:(UIImage *)image {
CGSize newSize = CGSizeMake(image.size.width + 50, image.size.height + 60);
UIGraphicsBeginImageContext(newSize);
CGRect rect = CGRectMake(25, 35, image.size.width, image.size.height);
[image drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextStrokeRectWithWidth(context, CGRectMake(25, 35, image.size.width, image.size.height), 50);
//CGContextSetShadowWithColor(context, CGSizeMake(0, -60), 5, [UIColor blackColor].CGColor);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result; }
PS:我沒有使用UIImageView,因爲我需要保留完整的圖像質量。
「UIImageView」以何種方式失去圖像質量? – 2012-08-07 03:59:24
我需要能夠在應用陰影/邊框後將圖像輸出到文件。您可以將UIImageView呈現爲PNG/BMP,但它們只能呈現UIImageView的大小。 – thedeveloper3124 2012-12-30 03:14:23