Mac OSX、ココアでの作業
階層化されたプロパティを持つ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 );
}