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

发布于 2024-09-14 07:42:54 字数 699 浏览 3 评论 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 );

    }

Working in Mac OSX, Cocoa

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.

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

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-09-21 07:42:54

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

您需要使用第三方 PSD - 阅读图书馆。

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

You'll need to use a third-party PSD-reading library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文