0
私はUIImagePickerControllerを使用しています。画像が選択されると、それをPNGに保存します。しかし何らかの理由で、私は保存されたイメージを読み込むことができません。ここでiPhoneに画像を読み込む方法
は私のコードです:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//
// Create a PNG representation of the edited image
//
UIImage *anImage = [info valueForKey:UIImagePickerControllerEditedImage];
NSData *imageData = UIImagePNGRepresentation(anImage);
//
// Save the image to the documents directory
//
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Get a unique filename for the file
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
NSString *fileName = [(NSString *)string autorelease];
fileName = [NSString stringWithFormat:@"images/%@", fileName];
fileName = [fileName stringByAppendingString:@".png"];
NSString *path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:fileName] ];
[imageData writeToFile:path atomically:YES];
NSLog(@"Wrote the imageData to a file at path: %@", path);
// TEST TO SEE IF THE FILE WAS WRITTEN CORRECTLY
UIImage *testImage = [UIImage imageWithContentsOfFile:path];
NSLog(@"testImage is %@", testImage);
そして、ここでは私のデバッガ出力です:
2010-12-28 16:29:08.676 Appster[6656:207] The imagePath is defined as: images/7ADB104E-DA45-4EE9-88DA-FF71B8D730CA.png
2010-12-28 16:29:08.712 Appster[6656:207] Wrote the imageData to a file at path: /Users/bschiff/Library/Application Support/iPhone Simulator/4.2/Applications/9F6FC2C7-9369-438C-AF8F-D5D25C72D8D7/Documents/images/FC94AA93-02EC-492A-A8FE-7D0C76E2C085.png
2010-12-28 16:29:08.715 Appster[6656:207] testImage is (null)