在我的应用程序中,我正在拍照并在图像视图中显示它。
现在我需要该图像的路径,以便将其上传到服务器。
我如何获得这条路?我尝试导入ALAsset框架,但没有称为my x code(4.2)iOS 5.0
的框架NSData *data = UIImagePNGRepresentation(imagePic.image);
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"upload.jpg"];
[data writeToFile:file atomically:YES];
[[EPUploader alloc] initWithURL:[NSURL URLWithString:@"myWebSite"]
filePath:@"file"
delegate:self
doneSelector:@selector(onUploadDone:)
errorSelector:@selector(onUploadError:)];
这就是我目前正在尝试的。
在iphone相机胶卷中,照片的硬编码路径是什么? “iphone / pictures / myPic”??所以我可以尝试上传与寻找路径分开。
请和谢谢
编辑:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
image2 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image2, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
imagePic.image = image2;
[picker release];
}
答案 0 :(得分:3)
图像视图没有路径,它在内存中。您必须保存从拍摄图像返回时获得的路径。在委托方法imagePickerController:didFinishPickingMediaWithInfo:
中,您可以在NSURL
中获得指向磁盘上图像的UIImagePickerControllerMediaURL
:
NSURL *imageURL = [info valueForKey:UIImagePickerControllerMediaURL];