2010-04-27 60 views
3

我使用的是Mac OS X 10.6 SDK ImageKit的IKSaveOptions使用添加的文件格式附件的NSSavePanel:有没有办法通过LZW压缩将ImageKit的IKSaveOptions默认初始化为TIFF?

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

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

我试图创建一个NSDictionary指定压缩= 5 ,但我似乎无法让IKSaveOptions在第一次出现NSSavePanel时显示Format:TIFF,Compression:LZW。我也尝试保存返回的imageProperties字典和userSelection字典,然后尝试在下次尝试提供它,但NSSavePanel始终默认使用Format:TIFF with Compression:None。

有谁知道如何自定义在附件视图中显示的默认格式/压缩?

我想将保存选项默认为TIFF/LZW,并且还希望下次恢复用户的最后一个文件格式选项。我能够使用imageUTType(例如kUTTypeJPEG,kUTTypePNG,kUTTypeTIFF等)来控制文件格式,但我仍然无法为TIFF或JPEG格式设置初始压缩选项。

感谢,

-Rei

回答

2

没有公共API来控制。但是,您可以通过NSSavePanel的附件视图对其进行修改。

实施例:

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]; 
      } 
     } 
    } 
} 
相关问题