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