Hello I am new to iPhone development so I could be doing this all wrong. I want to convert an image 3 times in a row but when I do it locks up the iphone until it finishes all 3 conversions. I have functions between the steps but they will not fire until the last image convert fires. This make more more sense if you read the code Notes below.
My questions are
Is there a faster way to convert the images? 2. How do I stop it from locking up so that it fires the code in order and the functions between the image converts fire inline?
- (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); }