您好,我是 iPhone 开发的新手,所以我可能做错了。我想连续转换图像 3 次,但是当我这样做时,它会锁定 iphone,直到它完成所有 3 次转换。我在步骤之间有功能,但在最后一个图像转换触发之前它们不会触发。如果您阅读下面的代码注释,这会更有意义。
我的问题是
有没有更快的方法来转换图像?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); }