与边界的图象在iphone

时间:2012-02-25 06:08:34

标签: iphone ios uiimageview

我想在我的iphone应用程序中对图像应用不同的边框。我从相机捕捉图像。现在我有一些不同的边框,我想将边框应用于图像。我怎么做 ??

1 个答案:

答案 0 :(得分:2)

- (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;
}