2010-03-24 44 views
3

我一直在嘗試將兩個UIImage混合約2天,並且我一直在收到一些BAD_ACCESS錯誤。首先,我有兩個具有相同方向的圖像,基本上我使用CoreGraphics來進行混合。CGContextDrawImage返回錯誤訪問

一個好奇的細節,每次我修改代碼,第一次在設備上編譯和運行代碼時,我可以做任何我想做的事情而不會遇到任何麻煩。一旦我重新啓動應用程序,就會出現錯誤並關閉程序。

任何人都可以給我一個燈?我試圖動態訪問baseImage大小,但它也給我訪問不好。

這是我如何做混合的片段。

UIGraphicsBeginImageContext(CGSizeMake(320, 480)); 
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextTranslateCTM(context, 0, 480); 
CGContextScaleCTM(context, 1.0, -1.0); 

CGContextDrawImage(context, rect, [baseImage CGImage]); 
CGContextSetBlendMode(context, kCGBlendModeOverlay); 
CGContextDrawImage(context, rect, [tmpImage CGImage]); 

[transformationView setImage:UIGraphicsGetImageFromCurrentImageContext()]; 
UIGraphicsEndImageContext(); 

補充:有時它會完美地工作,沒問題。有時它只是疊加而不混合。其他它會使iphone崩潰。

回答

4

顯然,主要的問題是每次編輯相同的CGImage。爲了擺脫它,我用

CGImageCreateCopy(sourceImage.CGImage); 

現在,我沒有得到崩潰了。如果有人能爲此提供更好的解釋,我很感激。

Regards

相關問題