2011-05-25 79 views

回答

0

您可以使用要保存的区域的剪贴蒙版来设置位图上下文。然后使用背景层的renderInContext方法绘制该上下文。

CGSize imageSize = CGSizeMake(960, 580); 

    UIGraphicsBeginImageContext(imageSize); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextClipToRect(context, CGRectMake(10,10,200,200); // whatever rect you want 

    [self.layer renderInContext:context]; 
    UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    // Save to camera roll 
    UIImageWriteToSavedPhotosAlbum(myImage, self, @selector(didSaveImage), null);