我需要围绕UIImage的边框。 UIImage被添加到PDF文件中。这是当前绘制图像的代码。
- (void) drawImage2
{
UIImage * demoImage = self.imageCopy;
NSData *jpegData = UIImageJPEGRepresentation(demoImage, 0.80);
CGDataProviderRef dp = CGDataProviderCreateWithCFData(( CFDataRef)jpegData);
CGImageRef cgImage = CGImageCreateWithJPEGDataProvider(dp, NULL, true, kCGRenderingIntentDefault);
[[UIImage imageWithCGImage:cgImage] drawInRect:CGRectMake(513, 314, 135, 135)];
}
关于我如何做到这一点的任何建议?我知道如何使用带有UIImageView的CALayers来实现它,但由于我没有视图,所以不确定。
答案 0 :(得分:5)
- (UIImage*)imageWithBorderFromImage:(UIImage*)source;
{
CGSize size = [source size];
UIGraphicsBeginImageContext(size);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
[source drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 0.5, 1.0, 1.0);
CGContextStrokeRect(context, rect);
UIImage *testImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return testImg;
}