目前,我可以在函数imagePickerController中检索用takePicture拍摄的照片,但是我想在这个函数之外使用它,当我尝试使用这个UIImage创建一个全局变量时,我没有任何图片。
那么我该如何使用这个UIImage?
我的代码:
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
screenshot = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
我在那里使用它:
NSData *imageData=[NSData dataWithData:UIImagePNGRepresentation(screenshot)];
NSURL *url = [NSURL URLWithString:@"http://myserver/test.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addData:imageData withFileName:@"tmp.jpg" andContentType:@"image/jpeg" forKey:@"userfile"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusString %@",[request responseString]);
screenshot是我的全局变量,我在服务器上收到一张空白图片。 提前谢谢。
答案 0 :(得分:0)
我假设您正在实施UIImagePickerControllerDelegate?如果是这样,当调用imagePickerController:didFinishPickingMediaWithInfo:时,您可以使用以下方法从传入的字典中获取图像:
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
如果要保留图像,请为viewcontroller类声明一个带保留的属性,并设置它:
self.image = [info valueForKey:UIImagePickerControllerOriginalImage];