1

如果你真的不明白,请检查我的应用程序(快速笔记!)但它就在这里。我的应用程序是一个笔记应用程序,因此它允许用户从下面几种不同的笔记颜色和设计中进行选择。当用户选择一个时,它会将上面的注释更改为他们设置的任何内容。所以我需要一个按钮来保存他们选择的图片,当离开视图并返回时,他们可以单击加载按钮,他们选择的相同图像将出现。我正在使用 Xcode 4.3。非常感谢!

这是我的保存代码:

-(IBAction)save123456 {
    NSBitmapImageRep *rep;
    NSData *data;
    NSImage *noteview;

    [self lockFocus];
    rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self frame]];
    [self unlockFocus];

    image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
    [image addRepresentation:rep];

    data = [rep representationUsingType: NSPNGFileType properties: nil];
    //save as png but failed
    [data writeToFile: @"asd.png" atomically: NO];

    //save as pdf, succeeded but with flaw
    data = [self dataWithPDFInsideRect:[self frame]];
    [data writeToFile:@"asd.pdf" atomically:YES];
}
And my load:
-(IBAction)load123456 {
NSImage loadedImage = [[NSImage alloc] initWithContentsOfFile: NSString* filePath]
}

我的存档中有很多错误代码。我的图像称为noteview。谢谢!!

4

1 回答 1

0

尝试改用

 [data writeToFile: @"asd.png" atomically: NO];

一个代码行

 [data writeToFile: @"asd.png" atomically: YES];

一些开源示例:

AGSimpleImageEditorView

iOS 中的图像编辑器

与图片合作的项目

于 2012-07-04T23:03:42.333 回答