psd使用CGImageRef创建具有图层属性的图像 [英] psd Image creation with layer properties using CGImageRef
问题描述
在Mac OSX中使用Cocoa
Working in Mac OSX, Cocoa
我有一个带分层属性的psd映像。
我想裁剪到裁剪矩形,并保存裁剪图像与原始图像的设置。
I have an psd image with layered property. I want to crop it to the crop rect and save this cropped image with the settings of original image.
我使用CGImageRef所有图像相关操作。
I am using CGImageRef for all the image related operations.
我已经封装了用于裁剪图像的代码,如下所示。但它无法创建分层图像。
I have enclosed the code i used to crop the image is given below. But it fails to create the layered image.
NSImage *img = [[NSImage alloc]initWithContentsOfFile:imagePath];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:[img TIFFRepresentation]];
CGImageRef imageRef = [rep CGImage];
CGImageRef cropedImage = CGImageCreateWithImageInRect(imageRef, cropRect);
CGImageDestinationRef idst = CGImageDestinationCreateWithURL( url, type, 1, NULL );
if( idst != NULL ) {
CGImageDestinationAddImage( idst, image, properties );
bool success = CGImageDestinationFinalize( idst );
}
推荐答案
在Mac OS X中使用内置API从PSD文件中读取单独的图层。一切都几乎肯定要去通过CGImageSource,并且CGImageSource不支持从PSD文件读取单独的图层。 (文档对 CGImageSourceGetCount
函数明确地说明了这一点,并且只使用 CGImageSourceCreateImageAtIndex
的实验。 )
There's no way to read separate layers from PSD files in Mac OS X with only built-in APIs. Everything is almost certainly going to go through CGImageSource, and CGImageSource does not support reading separate layers from PSD files. (The documentation says this explicitly for the CGImageSourceGetCount
function, and experimentation using only CGImageSourceCreateImageAtIndex
bears it out.)
您需要使用第三方PSD阅读库。
You'll need to use a third-party PSD-reading library.
这篇关于psd使用CGImageRef创建具有图层属性的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!