How can I convert png/jpeg to a .bmp image? I have tried the following solution but no luck:
CGImageRef sourceRef = source.CGImage;
size_t width = CGImageGetWidth(sourceRef);
size_t height = CGImageGetHeight(sourceRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
size_t bitsPerComponent = 8;
size_t bytesPerPixel = 4;
size_t bytesPerRow = (width * bitsPerComponent * bytesPerPixel + 7) / 8;
size_t dataSize = bytesPerRow * height;
unsigned char *data = malloc(dataSize);
memset(data, 0, dataSize);
CGContextRef context = CGBitmapContextCreate(data, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), sourceRef);
CGColorSpaceRelease(colorSpace);
unsigned char *bitmapData = (unsigned char *)CGBitmapContextGetData(context);