Xcode在Xcode iOS中保存和加载映像

Xcode在Xcode iOS中保存和加载映像,xcode,image,load,save,Xcode,Image,Load,Save,如果你真的不明白(快速笔记!),请检查我的应用程序,但它在这里。我的应用程序是一个notes应用程序,因此它允许用户从下面几种不同的备注颜色和设计中进行选择。当用户选择一个时,它会将上面的注释更改为他们设置的值。因此,我需要一个按钮,将保存他们选择的图片,当他们离开视图,回来,他们可以点击加载按钮,他们选择的相同的图像将出现。我使用的是Xcode 4.3。非常感谢 这是我的保存代码: -(IBAction)save123456 { NSBitmapImageRep *rep; N

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

试着改用

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

 [data writeToFile: @"asd.png" atomically: YES];
一些开源示例:


好的,当我这样做时,会出现很多错误。我会在错误的地方放一颗星星-(iAction)保存123456{*NSBitmapImageRep*rep;NSData*data;*NSImage*noteview;*[self lockFocus];*rep=[[NSBitmapImageRep alloc]initWithFocusedViewRect:[self frame]];*[self unlockFocus];*image=[[NSImage alloc]initWithSize:[rep size]]自动释放];*[image addRepresentation:rep];数据=[rep representationUsingType:NSPNGFileType属性:nil];//另存为png但失败[data writeToFile:@“asd.png”原子性:是];//另存为pdf,成功但有缺陷数据=[self-dataWithPDFInsideRect:[self-frame]];[data writeToFile:@“asd.pdf”原子性:是];]加载代码很好。试着在这里发布一个错误。对于一些提示,它们都类似于未声明的使用。你能给我一些关于如何保存和加载图像的演示代码吗?谢谢