Try this...
//First create a white image that has an equal size with your image.
CGImageRef sourceImage = yourImage.CGImage;
CFDataRef theData;
theData = CGDataProviderCopyData(CGImageGetDataProvider(sourceImage));
UInt8 *pixelData = (UInt8 *) CFDataGetBytePtr(theData);
int dataLength = CFDataGetLength(theData);
int red = 0;
int green = 1;
int blue = 2;
int alpha = 3;
for (int i = 0; i < (dataLength); i += 4) {
//create white pixels
int r = 255;
int b = 255;
int g = 255;
int al = 255;
pixelData[i + red] = r;
pixelData[i + blue] = b;
pixelData[i + green] = g;
pixelData[i + alpha] = al;
}
CGContextRef context;
context = CGBitmapContextCreate(pixelData,
CGImageGetWidth(sourceImage),
CGImageGetHeight(sourceImage),
8,
CGImageGetBytesPerRow(sourceImage),
CGImageGetColorSpace(sourceImage),
kCGImageAlphaPremultipliedLast);
CGImageRef newCGImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CFRelease(theData);
//Now that you have your image use CIFilter "CISourceOverCompositing".
//this adds your white image as the background.
UIImageOrientation originalOrientation = origim.imageOrientation;
data3 = UIImagePNGRepresentation(origim);
CIImage *result = [CIImage imageWithData:data3];
CIImage *result2 = [CIImage imageWithCGImage:newCGImage];
CIContext *contextt = [CIContext contextWithOptions:nil];
CIFilter *addBackground = [CIFilter filterWithName:@"CISourceOverCompositing"];
[addBackground setDefaults];
[addBackground setValue:result forKey:@"inputImage"];
[addBackground setValue:result2 forKey:@"inputBackgroundImage"];
result = [addBackground valueForKey:@"outputImage"];
CGImageRef imgRef = [contextt createCGImage:result fromRect:result.extent];
image = [[UIImage alloc] initWithCGImage:imgRef scale:1.0 orientation:originalOrientation];
CGImageRelease(imgRef);