在图形上下文中渲染叠加图像

时间:2013-10-03 07:36:42

标签: ios core-graphics ios7 overlay uiimagepickercontroller

我的应用可让用户使用相机叠加(工作部分)拍摄照片。然后他们可以保存图像,共享它,等等。我有一种方法可以将来自图像选择器的UIImage与UIView叠加层合并。

它已停止使用iOS 7了!我不明白为什么......

- (void)saveUserImageWithOverlay: (UIView*)overlay
{
    UIImage *image = self.userImage;

    CGSize outputImageSize = [[UIScreen mainScreen] bounds].size;       
    outputImageSize.height -= MENU_BAR_UI_OFFSET;

    CGSize userPhotoImageSize = [[UIScreen mainScreen] bounds].size;
    userPhotoImageSize.height = (image.size.height * userPhotoImageSize.width) / image.size.width;  

    if (NULL != UIGraphicsBeginImageContextWithOptions)
    {
        UIGraphicsBeginImageContextWithOptions(outputImageSize, NO, 0);
    }
    else
    {
        UIGraphicsBeginImageContext(outputImageSize);
    }

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetAlpha(context, 0.0);
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0);
    CGContextAddRect(context, CGRectMake(0.0, 0.0, outputImageSize.width, outputImageSize.height));
    CGContextDrawPath(context, kCGPathFill);

    [image drawInRect:CGRectMake(2.0,
                                 ((outputImageSize.height - userPhotoImageSize.height) / 2.0) +2.0,
                                 userPhotoImageSize.width -4.0, 
                                 userPhotoImageSize.height -4.0)];


    [self renderView:overlay inContext:context];

    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    self.editedImage = screenshot;
}

生成的图像仅包含照片(无覆盖!)。为什么?!? 我尝试只渲染叠加层。有用。 我尝试删除BLACK rect背景。它有效。

为什么黑色矩形隐藏了叠加层?

0 个答案:

没有答案