よくわからない場合は、私のアプリをチェックしてください (クイック ノート!)。私のアプリはメモアプリなので、ユーザーは以下のいくつかの異なる種類のメモの色とデザインから選択できます。ユーザーがいずれかを選択すると、上記のメモが設定されたものに変更されます。そのため、選択した画像を保存するボタンが必要です。ビューを離れて戻ってきたときに、読み込みボタンをクリックすると、選択した同じ画像が表示されます。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]
}
セーブに非常に多くのエラー コードが表示されます。私の画像はノートビューと呼ばれています。ありがとう!!