首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不含ImageKit NSSavePanel的可可节

不含ImageKit NSSavePanel的可可节
EN

Stack Overflow用户
提问于 2016-11-08 01:11:42
回答 1查看 87关注 0票数 0

那么,有没有一种方法可以在不向用户显示NSSavePanel的情况下保存经过编辑的图像?

也就是说,许多应用程序为用户提供了“保存”或“另存为.”的选项。其中"Save“只是覆盖了保存文件名的文件和”另存为.“显示包含所有选项的完整NSSavePanel。

我有一个应用程序调用ImageKit以允许编辑图像,并且我希望允许用户单击按钮或键命令来保存,而不需要面板。没有对话,没有通知,只需单击“保存”,图像文件就会被新编辑的文件覆盖。

我知道如何以这种方式保存文本文件,但我不确定如何从IKImageView中编辑图像。

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-08 02:34:43

所以我就一起绕过了NSSavePanel,直接去了GCImageDest:

代码语言:javascript
复制
- (IBAction)saveWithNoPanel: (id)sender
{
    _saveOptions = [[IKSaveOptions alloc] initWithImageProperties: _imageProperties
                                                      imageUTType: _imageUTType];

    NSString * url=[[NSUserDefaults standardUserDefaults] objectForKey:@"photoPath"];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];
    NSString * yearString = [formatter stringFromDate:[NSDate date]];

    NSString * fileName = [[_imageWindow representedFilename] lastPathComponent];
    //NSLog(@"Filename: %@",fileName);
    NSString * photoUrl =[NSString stringWithFormat:@"%@%@%@%@%@",url,@"/",yearString,@"/",fileName];
    //NSLog(@"photourl: %@",photoUrl);

    NSString * newUTType = [_saveOptions imageUTType];
    CGImageRef image;

    image = [_imageView image];

        if (image)
        {
            NSURL * url =[NSURL fileURLWithPath: photoUrl];
            //NSLog(@"URL: %@",url);

            CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)url,
                                                                         (CFStringRef)newUTType, 1, NULL);

            if (dest)
            {
                CGImageDestinationAddImage(dest, image,
                                           (CFDictionaryRef)[_saveOptions imageProperties]);
                CGImageDestinationFinalize(dest);
                CFRelease(dest);
            }
        } else
        {
            NSLog(@"*** saveImageToPath - no image");
        }
    [pwPhotoPathTextField setStringValue:[NSString stringWithFormat:@"%@%@",photoUrl]];
    [_imageWindow orderOut:self];
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40477382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档