Trying to resize an NSImage which turns into NSData

Posted by Ricky on Stack Overflow See other posts from Stack Overflow or by Ricky
Published on 2010-03-28T03:39:04Z Indexed on 2010/03/28 3:43 UTC
Read the original article Hit count: 531

Filed under:
|
|

I have an NSImage which I am trying to resize like so;

NSImage *capturePreviewFill = [[NSImage alloc] initWithData:previewData];
NSSize newSize;
newSize.height = 160;
newSize.width = 120;
[capturePreviewFill setScalesWhenResized:YES];
[capturePreviewFill setSize:newSize];

NSData *resizedPreviewData = [capturePreviewFill TIFFRepresentation]; 
resizedCaptureImageBitmapRep = [[NSBitmapImageRep alloc] initWithData:resizedPreviewData];
[saveData writeToFile:@"/Users/ricky/Desktop/Photo.jpg" atomically:YES];

My first issue is that my image gets squashed when I try to resize it and don't conform to the aspect ratio. I read that using -setScalesWhenResized would resolve this problem but it didn't.

My second issue is that when I try to write the image to a file, the image isn't actually resized at all.

Thanks in advance, Ricky.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsimage