1

我需要 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 来做到这一点,但在这里不确定,因为我没有视图。

4

1 回答 1

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;
}
于 2013-04-17T09:02:06.377 回答