psd Image creation with layer properties using CGImageRef

戏子无情 提交于 2019-12-11 18:24:17

问题


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

    }

回答1:


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.



来源:https://stackoverflow.com/questions/3456560/psd-image-creation-with-layer-properties-using-cgimageref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!