2

I'm working on an mac application and I work with images. The quality and the ICC profile are really important. Sometimes I need to resize the images because I send them to a server and they cant be too heavy.

I dont have problem with the resizing itself, but I use a copy of the image and I lose the ICC profile : for exemple I got a sRGB image, but after the resize it takes the profile of the screen, and I want to keep the sRGB profile.

    -(NSData*)resizeImage: (NSSize)newSize { // I calcul newSize before and the values are good
    NSImage *smallImage = [[NSImage alloc] initWithSize: newSize];
    [smallImage lockFocus];
    [image setSize: newSize]; //image is the image I want to resize
    [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
    [image drawAtPoint:NSZeroPoint fromRect:CGRectMake(0, 0, newSize.width, newSize.height) operation:NSCompositeCopy fraction:1.0];
    [smallImage unlockFocus];
    return ([self returnImageAsJpeg:smallImage]);
}

And here's the

-(NSData *) returnImageAsJpeg:(NSImage *)smallImage

method :

-(NSData *)returnImageAsJpeg:(NSImage *)smallImage {
    NSData *imageData = [smallImage TIFFRepresentation];
    NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
    NSNumber *compressionFactor = [NSNumber numberWithFloat:0.6];
    NSDictionary *imageProps = [NSDictionary dictionaryWithObject:compressionFactor forKey:NSImageCompressionFactor];
    imageData = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
    return (imageData);
}

I know the code is not really clean, but my question is : how can resize a NSImage without losing its properties. Here I make a copy in smallImage and I use it, but the properties are loss.

Thank you for helping.

1
  • Hey there, did you solved it? We have the exact same issue!
    – Roi Mulia
    Nov 20, 2018 at 16:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.