| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
| Hi all, I'm using the Lanczos Scale Transform filter and the Sharpen Luminance filter to create thumb nails of a bunch of images (given as NSImage). This works like a charm! Now I wanted to use the CICrop filter to crop the images to the aspect ratio of the desired thumb nail size at first. And this does not work. What I'm doing is the following: At first, calculate the cropped size and "crop origin": float imageRatio = _imageSize.width / _imageSize.height; float scaledRatio = _outSize.width / _outSize.height; NSSize croppedSize; NSPoint cropOrigin = NSZeroPoint; if( imageRatio >= scaledRatio ) { croppedSize.width = floor(_imageSize.height*scaledRatio); croppedSize.height = _imageSize.height; cropOrigin.x = floor(.5*(_imageSize.width-croppedSize.width)); } else { croppedSize.width = _imageSize.width; croppedSize.height = floor(_imageSize.width/scaledRatio); cropOrigin.y = floor(.5*(_imageSize.height-croppedSize.height)); } Then apply the CICrop filter: CIImage *cii = [CIImage imageWithData:[_image TIFFRepresentation]]; [_cropFilter setDefaults]; [_cropFilter setValue:cii forKey:@"inputImage"]; [_cropFilter setValue:[CIVector vectorWithX:cropOrigin.x Y:cropOrigin.y Z:croppedSize.width W:croppedSize.height] forKey:@"inputRectangle"]; apply some other filters… and convert the result to a NSImage instance: cii = [_sharpenFilter valueForKey:@"outputImage"]; CGRect imageExtent = [cii extent]; result = [[[NSImage alloc] initWithSize:NSMakeSize(imageExtent.size.width, imageExtent.size.height)] autorelease]; [result addRepresentation:[NSCIImageRep cii]]; What I get is a somewhat shifted image. Does anybody know what I'm doing wrong? Any help will be greatly appreciated! Thanks in advance, Thomas |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden This email sent to email@hidden
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.