Is there a way to initialize ImageKit's IKSaveOptions to default to TIFF with LZW compression?

450 views Asked by At

I'm using Mac OS X 10.6 SDK ImageKit's IKSaveOptions to add the file format accessory to an NSSavePanel using:

- (id)initWithImageProperties:(NSDictionary *)imageProperties imageUTType:(NSString *)imageUTType;

and

- (void)addSaveOptionsAccessoryViewToSavePanel:(NSSavePanel *)savePanel;

I have tried creating an NSDictionary to specify Compression = 5, but I cannot seem to get the IKSaveOptions to show Format:TIFF, Compression:LZW when the NSSavePanel first appears. I've also tried saving the returned imageProperties dictionary and the userSelection dictionary, and then tried feeding that back in for the next time, but the NSSavePanel always defaults to Format:TIFF with Compression:None.

Does anyone know how to customize the default format/compression that shows up in the accessory view?

I would like to default the save options to TIFF/LZW and furthermore would like to restore the user's last file format choice for next time. I am able to control the file format using the imageUTType (e.g. kUTTypeJPEG, kUTTypePNG, kUTTypeTIFF, etc) but I am still unable to set the initial compression option for TIFF or JPEG formats.

Thanks,

-Rei

1

There are 1 answers

0
Marek H On

There is no public API to control this. However, you can modify it through accessory view of the NSSavePanel.

Example:

self.saveOptions = [[IKSaveOptions alloc] initWithImageProperties:nil
                                                            imageUTType:(NSString *)kUTTypeTIFF];
[self.saveOptions addSaveOptionsAccessoryViewToSavePanel:savePanel];


// find compression options popup button in accessory view, select desired compression
// correct title depends on localization -> be carefull with LZW and tag
NSView *accessoryView = [savePanel accessoryView];
NSArray *accessorySubViews = [accessoryView subviews];

for (id view in accessorySubViews) {

    if([view isKindOfClass:[NSPopUpButton class]]){
        NSPopUpButton *popupButton = (NSPopUpButton *)view;
        NSArray *menuItems =[[popupButton menu] itemArray];
        for (NSMenuItem *menutItem in menuItems) {
            if([[menutItem title] isEqualToString:@"LZW"]) {
                //make sure you reverse engineer tags for
                [popupButton selectItemWithTitle:@"LZW"];
                id target = [menutItem target];
                SEL action = [menutItem action];
                [target performSelector:action withObject:popupButton];
            }
        }
    }
}