Reputation: 111
I am needing a border around a UIImage. The UIImage is added to a PDF file. Here is the code for drawing the image currently.
- (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)];
}
Any suggestions for how I can do this? I know how to do it using CALayers with a UIImageView, but not sure here since I don't have the view.
Upvotes: 1
Views: 4256
Reputation: 1028
- (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;
}
Upvotes: 5