让photoshop阅读我的多层CGImageRef tiff

时间:2012-10-22 19:57:17

标签: xcode photoshop tiff cgimageref multi-layer

Photoshop让我很困惑。

我可以从photoshop创建一个多层tif图像并将其读入我的程序(可可构建)

我可以在程序中创建一个多层tif,并通过tiffutil读取它。

然而,

photoshop将不会将我的文件识别为多层tif。只有第一张图片进来。

我需要包含哪些信息?我该怎么做呢?当我写出一个gif(kUTTypeGIF)而不是一个tif(kUTTypeTIFF)时,一切都很好。


这里有一些代码来展示我正在做的事情......(使用Xcode 4.1 CoreFoundation) 下面的代码应该包含3个JPEG图像并创建单独的层来写出多层tiff文件。它适用于GIF但不适用于TIFF

// create CFURLRef for 3 separate images.
NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"1image" ofType:@"jpg"];
CFURLRef url1 = (CFURLRef)[NSURL fileURLWithPath:filePath1];

NSString *filePath2 = [[NSBundle mainBundle] pathForResource:@"2image" ofType:@"jpg"];
CFURLRef url2 = (CFURLRef)[NSURL fileURLWithPath:filePath2];

NSString *filePath3 = [[NSBundle mainBundle] pathForResource:@"3image" ofType:@"jpg"];
CFURLRef url3 = (CFURLRef)[NSURL fileURLWithPath:filePath3];


// setup to write to data object
NSMutableData          * finalImageData = [NSMutableData data];
CGImageSourceRef       imageSourceRef = nil;
// this one does not work
CGImageDestinationRef  imageDestRef = CGImageDestinationCreateWithData((CFMutableDataRef)finalImageData, kUTTypeTIFF, 3, nil);
// This one works
// CGImageDestinationRef  imageDestRef = CGImageDestinationCreateWithData((CFMutableDataRef)finalImageData, kUTTypeGIF, 3, nil);

// build the final image
imageSourceRef = CGImageSourceCreateWithURL(url1, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

imageSourceRef = CGImageSourceCreateWithURL(url2, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

imageSourceRef = CGImageSourceCreateWithURL(url3, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

CGImageDestinationFinalize(imageDestRef);
CFRelease(imageDestRef);
CFRelease(imageSourceRef);

// write out the final image data
[finalImageData writeToFile:@"outfile.tif" atomically:YES];
// [finalImageData writeToFile:@"outfile.gif" atomically:YES];

0 个答案:

没有答案