你好,我是新的iPhone開發,所以我可以做到這一切都是錯誤的。我想連續轉換一次圖像3次,但是當我這樣做時,它會鎖定iphone,直到它完成所有3次轉換。我有步驟之間的功能,但他們不會開火,直到最後一個圖像轉換火災。如果你閱讀下面的代碼註釋,這會更有意義。Iphone與圖像工作停止所有進程
我的問題是
是否有到圖像轉換更快的方法? 2.如何阻止它鎖定,以便它按順序觸發代碼,並且圖像之間的函數將內聯轉換爲火線?
- (IBAction)ColorFun1 { // // ANY CODE IN THIS location will not fire until 3rd convert is finished // // Image to convert UIImage *originalImage = imageView.image; // 1st Convert CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray(); CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone); CGContextSetInterpolationQuality(context, kCGInterpolationHigh); CGContextSetShouldAntialias(context, NO); CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]); CGImageRef bwImage = CGBitmapContextCreateImage(context); // CGContextRelease(context); CGColorSpaceRelease(colorSapce); // UIImage *resultImageBW = [UIImage imageWithCGImage:bwImage]; // This is result B/W image. [fxImage2View setImage:resultImageBW]; // // ANY CODE IN THIS location will not fire until 3rd convert is finished // // // // 2nd Convert // UIGraphicsBeginImageContext(resultImageBW.size); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); [resultImageBW drawInRect:CGRectMake(0, 0, resultImageBW.size.width, resultImageBW.size.height)]; CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference); CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor grayColor].CGColor); CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, resultImageBW.size.width, resultImageBW.size.height)); UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext(); [fxImage1View setImage:returnImage]; UIGraphicsEndImageContext(); // // // // ANY CODE IN THIS location will not fire until 3rd convert is finished // // // // 3rd Convert // UIGraphicsBeginImageContext(resultImageBW.size); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); [resultImageBW drawInRect:CGRectMake(0, 0, resultImageBW.size.width, resultImageBW.size.height)]; CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeSoftLight); CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor colorWithRed:40 green:20 blue:0 alpha:1].CGColor); CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, resultImageBW.size.width, resultImageBW.size.height)); returnImage = UIGraphicsGetImageFromCurrentImageContext(); [fxImage3View setImage:returnImage]; UIGraphicsEndImageContext(); CGImageRelease(bwImage); }
+1,GCD是正確的方法。 –