I’m new to cocoa and what I’m trying to do is resize a NSImage, but it looks like I’m doing something wrong as my image’s don’t get resized. I had a look at the other questions and this approach looked like it should work:
- (void)scaleIcons:(NSString *)outputPath{
NSImage *anImage;
NSSize imageSize;
NSString *finalPath;
anImage = [self image];
imageSize = [anImage size];
imageSize.width = 512;
imageSize.height = 512;
[anImage setSize:imageSize];
finalPath = [outputPath stringByAppendingString:@"/icon_512x512.png"];
NSData *imageData = [anImage TIFFRepresentation];
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:imageData];
NSData *dataToWrite = [rep representationUsingType:NSPNGFileType properties:nil];
[dataToWrite writeToFile:finalPath atomically:NO];
}
everything works, except the fact that my images don’t get scaled. Could someone help a bit?
So your code snippet is omitting the operations actually required to scale/transform the image. Pass your image through a method such as this one before you try to save it:
If you integrate this into your existing method: