Reduce the size of an NSImage
Reduce the size of an NSImage
- Subject: Reduce the size of an NSImage
- From: Simon Raisin <email@hidden>
- Date: Mon, 31 May 2010 08:38:43 -0400
Hi,
I am trying to reduce the size of an NSImage by 50% and then save the
reduced image out to disk. The following code does not reduce the image.
Should I be going about this a different way?
Thanks!
Simon
NSImage* inputImage = [[NSImage alloc] initWithContentsOfFile:[fileNames
objectAtIndex:0]];
NSSize halfSize = [inputImage size];
halfSize.height = (int)(halfSize.height / 2);
halfSize.width = (int)(halfSize.width / 2);
[inputImage setScalesWhenResized:YES];
[inputImage setSize:halfSize];
NSBitmapImageRep* imageRepx = [NSBitmapImageRep
imageRepWithData:[inputImage TIFFRepresentation]];
NSDictionary *imagePropsx = [NSDictionary dictionaryWithObject:[NSNumber
numberWithFloat:0.9]
forKey:NSImageCompressionFactor];
NSData* outputImageDatax = [imageRepx representationUsingType:NSJPEGFileType
properties:imagePropsx];
[outputImageDatax writeToFile:@"resizedimage.jpg" atomically:YES];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden