【问题标题】:Getting errors while blending 2 image混合 2 图像时出错
【发布时间】:2011-11-25 04:25:11
【问题描述】:

我在输出视图中收到这些错误。我正在尝试将图像混合到另一个图像上,并且我的程序也提供了所需的输出。只是想知道为什么会发生这些错误以及如何删除它们?我的代码写在下面:
错误:

<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetBlendMode: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0

代码:

(UIImage*) blendImage
{
    CGFloat ox = self.scrollView.contentOffset.x;
    CGFloat oy = self.scrollView.contentOffset.y;
    CGFloat zoomScale = self.scrollView.zoomScale;
    CGFloat cx = (ox + self.cropRectangleButton.frame.origin.x -75.0f) *2.0f / zoomScale;
    CGFloat cy = (oy + self.cropRectangleButton.frame.origin.y -85.0f )*2.0f / zoomScale;
    CGFloat cw = 600.0f / zoomScale;
    CGFloat ch = 600.0f / zoomScale;
    CGRect cropRect = CGRectMake(cx, cy, cw, ch);
    UIImage *maskImage=[UIImage imageNamed:@"teeth02"];
    [maskImage drawInRect:cropRect];
    [self.photo drawInRect:imageViewFrame];
    UIGraphicsBeginImageContext(self.photo.size);
    [self.photo drawAtPoint:CGPointMake(0,0)];
    [maskImage drawAtPoint:CGPointMake(cx, cy)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

【问题讨论】:

  • 在哪里以及如何?你能帮忙吗?我是新手

标签: iphone image blend


【解决方案1】:

您似乎在图形上下文之外调用了[maskImage drawInRect:cropRect];drawInRect: 需要设置当前上下文

【讨论】:

  • 好的,谢谢。问题已经解决了。我移动了 [maskImage drawInRect:cropRect];和 [self.photo drawInRect:imageViewFrame];在行之间 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();现在问题解决了
猜你喜欢
  • 2014-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 2018-11-04
  • 1970-01-01
  • 2016-01-24
相关资源
最近更新 更多