1
如果您不太明白,請查看我的應用程序(快速註釋!我的應用程序是一個便籤應用程序,因此它允許用戶從下面的幾種不同的筆記顏色和設計中進行選擇。當用戶選擇一個時,它會將上面的註釋更改爲他們設置的值。所以我需要一個按鈕來保存他們選擇的圖片,當離開視圖並回來時,他們可以點擊加載按鈕,他們選擇的圖像將會出現。我正在使用Xcode 4.3。非常感謝!Xcode在Xcode中保存並加載圖像iOS
這裏是我的節省代碼:
-(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。謝謝!!
好的,當我這樣做時,我得到了很多錯誤。我會在出現錯誤的地方放一顆星星。 - (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]; – Nicholas
data = [rep representationUsingType:NSPNGFileType properties:nil]; //另存爲png,但失敗 [data writeToFile:@「asd.png」atomically:YES]; //另存爲pdf,成功但存在缺陷 data = [self dataWithPDFInsideRect:[self frame]]; [data writeToFile:@「asd.pdf」atomically:YES]; } 加載代碼很好。 – Nicholas
嘗試在這裏發佈錯誤。對於一些提示,http://stackoverflow.com/questions/11005317/how-to-find-the-location-of-error-in-xcode/11007493#11007493 – CReaTuS