0

在 Mac OSX、Cocoa 中工作

我有一个具有分层属性的 psd 图像。我想将它裁剪到裁剪矩形并使用原始图像的设置保存这个裁剪的图像。

我将 CGImageRef 用于所有与图像相关的操作。

我附上了我用来裁剪图像的代码,如下所示。但它无法创建分层图像。

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 );

    }
4

1 回答 1

1

在 Mac OS X 中,仅使用内置 API 无法从 PSD 文件中读取单独的图层。几乎可以肯定一切都会通过 CGImageSource,而 CGImageSource 不支持从 PSD 文件中读取单独的图层。(文档明确说明了该CGImageSourceGetCount功能,并且仅使用实验CGImageSourceCreateImageAtIndex证明了这一点。)

您需要使用第三方 PSD 阅读库。

于 2010-08-11T10:02:15.137 回答