开发者

iOS support for Canon RAW format?

I know the iPad can read Canon RAW (.CR2) files when used with the Camera Kit but is any of that file format reading accessible to an iOS developer? Or are we just limited 开发者_如何学JAVAto things supported in the UIImage Class Reference document?

(https://developer.apple.com/documentation/uikit/uiimage)


For something like this, Apple's image APIs are not going to be sufficient for what you need. However, there are a few third party APIs that should work with the iPhone. Libraw is a good one that I found that has a C interface. Since Objective-C is a strict superset of C, you will probably be able to use it in your iOS application.

From what I see in their docs, you might be able to write a CR2 image as a TIFF, then decode it as a UIImage like this:

NSString * cr2Path = @"path/to/cr2/file";
NSString * tiffPath = [NSTemporaryDirectory stringByAppendingPathComponent:@"x.tiff"];

libraw_data_t * cr2Data = libraw_init(0);
libraw_open_file(cr2Data, [cr2Path UTF8String]);
libraw_unpack(cr2Data);
// setup encoding params
cr2Data->params.output_tiff = 1;
cr2Data->params.use_camera_wb = 1;
// encode and write as tiff
libraw_dcraw_process(cr2Data);
libraw_dcraw_ppm_tiff_writer(cr2Data, [tiffPath UTF8String]);
libraw_recycle(cr2Data); // free the memory
// load the UIImage
UIImage * myImage = [[UIImage alloc] initWithContentsOfFile:tiffPath];
// use myImage here ...
[myImage release];

From what I have seen, it looks like you will be able to download it here and then add the src files from the src/, libraw/, dcraw/, and internal/ directories to your Xcode project. Hopefully you will not run into any weird linking/compiling issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜