0

On MacOS, .heic image files can contain one light and one dark version. This can be seen for system wallpapers using open: for example open /System/Library/Desktop\ Pictures/Dome.heic

The Preview app displays both versions. My goal is to be able to access them using Objective-C, as I would like to save both light and dark versions to .jpg format.

Following snippet succeeds in extracting the light version and saving it to disk:

NSString* wallpaper_path = /* insert source path here */;
NSString* converted_path_str = /* insert destination path here */;

NSImage* image = [[[NSImage alloc] initWithContentsOfFile:wallpaper_path] autorelease];
NSData* data = [image TIFFRepresentation];
NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:data];
NSDictionary* properties =[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
data = [rep representationUsingType:NSJPEGFileType properties:properties];
[data writeToFile:converted_path_str atomically:NO];

However I cannot find how to access the dark version using NSImage, NSImageRep or NSBitmapImageRep. As Preview succeeds in doing it, I think it's possible though. I just don't know how to do.

Yuufo
  • 11
  • 1
  • 3
  • What is the value of `image.representations.count`? – Willeke Aug 05 '21 at 15:32
  • It is 2 for Light and Dark desktop pictures, and 8 for Dynamic desktop ones. Discarding the unwanted representation of L&D pictures before writing to disk solves my issue. – Yuufo Aug 06 '21 at 07:13
  • Why are you converting to TIFF instead of converting the two representations directly to JPEG? – Willeke Aug 06 '21 at 07:22

0 Answers0