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