cocoa - 使用 CGImageRef 创建具有图层属性的 psd 图像

标签 cocoa macos cgimage psd

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

    }

最佳答案

仅使用内置 API 无法从 Mac OS X 中的 PSD 文件中读取单独的图层。几乎可以肯定,所有内容都会经过 CGImageSource,而 CGImageSource 不支持从 PSD 文件中读取单独的图层。 ( The documentation says this explicitly for the CGImageSourceGetCount function ,仅使用 CGImageSourceCreateImageAtIndex 的实验证明了这一点。)

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

关于cocoa - 使用 CGImageRef 创建具有图层属性的 psd 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3456560/

相关文章:

ios - 使用 AVFoundation 混合图像和视频

objective-c - 从 NSViewController 设置 NSWindow 内容 View

ios - Xcode - 如何修复 'NSUnknownKeyException' ,原因 : … this class is not key value coding-compliant for the key X"error?

macos - 在终端获取下个月

macos - Mac CoreLocation 服务不请求权限

ios - iOS 图像分割

objective-c - Xcode4 "Build Finished"HUD

objective-c - CPTBarPlot 字段的面积?

macos - 只需在 Cocoa 中制作一个标签说“Hello World”(Mac 编程)

objective-c - 新的 CALayer.contents 在调整 View 大小之前不会显示