有没有办法将 ImageKit 的 IKSaveOptions 初始化为默认为 LZW 压缩的 TIFF?

发布于 2024-08-30 20:38:01 字数 757 浏览 14 评论 0原文

我正在使用 Mac OS X 10.6 SDK ImageKit 的 IKSaveOptions 将文件格式附件添加到 NSSavePanel 使用:

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

并且

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

我尝试创建一个 NSDictionary 来指定 Compression = 5,但我似乎无法让 IKSaveOptions 显示 Format:TIFF, Compression :LZW 当 NSSavePanel 第一次出现时。我还尝试保存返回的 imageProperties 字典和 userSelection 字典,然后尝试下次将其返回,但 NSSavePanel 始终默认为 Format:TIFF 和 Compression:None。

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

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

谢谢,

-Rei

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2024-09-06 20:38:01

没有公共 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];
            }
        }
    }
}

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];
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文