2011-11-25 30 views
0

我在輸出視圖中看到這些錯誤。我試圖將圖像混合到另一個圖像上,我的程序也提供了所需的輸出。只是想知道爲什麼會出現這些錯誤,以及如何刪除它們?我的代碼編寫如下:
錯誤:混合2圖像時出錯

<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; 
} 
+0

哪裏和如何?你能幫忙嗎?我是新來的 –

+0

對不起誤解 – Aravindhan

回答

1

它看起來像你打電話[maskImage drawInRect:cropRect];外的圖形上下文。 drawInRect:要求要設置的當前上下文

+0

是的,謝謝。問題已經解決了。 我搬了[maskImage drawInRect:cropRect];和[self.photo drawInRect:imageViewFrame];在行之間UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 現在問題已解決 –