I am developing an iPad app which presents pictures from a photographer. Those photos are uploaded on a webserver, and served directly through the app, where they are downloaded and displayed using the method below :
if([[NSFileManager defaultManager] fileExistsAtPath:[url path]]){
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef cgImage = nil;
if(source){
cgImage = CGImageSourceCreateImageAtIndex(source, 0, (CFDictionaryRef)dict);
}
UIImage *retImage = [UIImage imageWithCGImage:cgImage];
if(cgImage){
CGImageRelease(cgImage);
}
if(source){
CFRelease(source);
}
return retImage;
}
I can observe a serious change in the display of the photos’ colours between the original picture (which is the same when displayed from the disk or from the web on my Mac and the photographer’s Mac) and on the iPad (the result is wrong in the app and even in Safari).
After some search I found some posts explaining how iDevices do not use embedded color profile, so I found I was going this way. The photos are saved using the following info :
I found out on some articles (for example this link from imageoptim or analogsenses) that I should save the picture for device export by converting it to sRGB, without embedding the color profile, but I cant find out how could I do that ? Each time I tried (I don’t have photoshop, so I used command line ImageMagick), the resulting picture has the following information, and is still not displayed correctly on my iPad (and any other iPads I’ve tested) :
I would like to transform it to display it correctly, any Idea would be really welcomed 🙂
[EDIT] I have succeeded to obtain a correct image using “save for web” options of photoshop using the following parameters :But I’m still unable to apply those settings automatically to all my pictures.
3
Answers
To read an image, just use:
As for the color profile issue, try the
sips
command-line tool to fix the image files. Something like:You can get first the color space through CGImage.
And depping of the colorSpace apply a format conversion. So to get the color space of an image, you’d do:
Note: make sure to follow the get/create/copy rules for CG objects.
Color conversion to RGB8 (also can be applied to RGB16 or RGB32, changing the bits per component in the method
newBitmapRGBA8ContextFromImage
):ImageHelper.h
ImageHelper.m
@PhilippeAuriach
I think you might have problem with
[UIImage imageWithCGImage:cgImage]
, My suggestion is use[UIImage imageWithContentsOfFile:path]
instead of above.Below code might be help you.