Xcode在Xcode iOS中保存并加载图像

时间:2012-07-04 20:40:53

标签: xcode image load save

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

1 个答案:

答案 0 :(得分:0)

尝试使用

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

代码行

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

一些开源示例:

AGSimpleImageEditorView

image editors in iOS

projects with work with Pictures