我正在构建一个严重依赖 Apples SquareCam 示例代码的应用程序。他们通过使用 AVFoundation 的自定义相机设置拍摄照片。他们将照片保存到相机胶卷。我想将它存储在文档目录中。似乎他们将图像数据存储在 aCFMutableDataRef
但我不确定如何将其转换为图像。有任何想法吗?
苹果的代码:
CFMutableDataRef destinationData = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef destination = CGImageDestinationCreateWithData(destinationData,
CFSTR("public.jpeg"),
1,
NULL);
BOOL success = (destination != NULL);
require(success, bail);
const float JPEGCompQuality = 0.85f;
CFMutableDictionaryRef optionsDict = NULL;
CFNumberRef qualityNum = NULL;
qualityNum = CFNumberCreate(0, kCFNumberFloatType, &JPEGCompQuality);
if ( qualityNum ) {
optionsDict = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if ( optionsDict )
CFDictionarySetValue(optionsDict, kCGImageDestinationLossyCompressionQuality, qualityNum);
CFRelease( qualityNum );
}
CGImageDestinationAddImage( destination, cgImage, optionsDict );
success = CGImageDestinationFinalize( destination );
if ( optionsDict )
CFRelease(optionsDict);
require(success, bail);
CFRetain(destinationData);
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library writeImageDataToSavedPhotosAlbum:(id)destinationData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
if (destinationData)
CFRelease(destinationData);
}];
[library release];