0

我正在构建一个严重依赖 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];
4

1 回答 1

0

CFMutableDataRef是免费桥接到NSMutableData,因此您可以将CFMutableDataRefto NSMutableDataor NSData(或将其分配给该类型的变量)并调用其中一个writeToFile:orwriteToURL:方法将其存储到文件系统并查看是否会产生图像文件。

于 2013-04-28T19:49:38.763 回答