I have a project. It basically takes photo from iPhone camera and applies some effects on photo. Before I apply effect I use core graphics to scale image to appropriate size. After scaling and rotating image I use Accelerate framework(vImage) in order to create effect. My problem is after applying effect it is ended up some bluish image. However If I don't scale image with core graphics this bluish looks doesn't happen.
Scaling code that I use is from this post.
And here is my code that applies effect:
- (UIImage *)applyFiltertoImage:(UIImage *)img
{
CGImageRef image = img.CGImage;
vImage_Buffer inBuffer, outBuffer;
void *pixelBuffer;
CGDataProviderRef inProvider = CGImageGetDataProvider(image);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
inBuffer.width = CGImageGetWidth(image);
inBuffer.height = CGImageGetHeight(image);
inBuffer.rowBytes = CGImageGetBytesPerRow(image);
inBuffer.data = (void *)CFDataGetBytePtr(inBitmapData);
pixelBuffer = malloc(CGImageGetBytesPerRow(image) * CGImageGetHeight(image));
if (pixelBuffer == NULL) {
NSLog(@"No buffer");
}
outBuffer.data = pixelBuffer;
outBuffer.width = CGImageGetWidth(image);
outBuffer.height = CGImageGetHeight(image);
outBuffer.rowBytes = CGImageGetBytesPerRow(image);
vImageConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, self.kernel, self.size, self.size, self.divisor, NULL, kvImageEdgeExtend);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(outBuffer.data,
outBuffer.width,
outBuffer.height,
8,
outBuffer.rowBytes,
colorSpace,
kCGImageAlphaNoneSkipLast);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
UIImage *blurredImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace);
free(pixelBuffer);
CFRelease(inBitmapData);
CGImageRelease(imageRef);
return blurredImage;
}
Usually, a strong color tint means that the color channel order was lost in translation somewhere along the way, for example you created a CG image with BGRA data, but it was actually ARGB.
Have you looked at vImage_Utilities.h?