Currently, I can retrieve the picture taken with takePicture in the function imagePickerController, but I want to use it outside of th开发者_开发百科is function, and when I try to make a global variable to use this UIImage, I don't have any picture.
So how can I use this UIImage ?My code :
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
screenshot = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
and I use it there :
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 is my global variable and I receive a blank image on my server. Thanks in advance.
I'm assuming you are implementing UIImagePickerControllerDelegate? If so, when imagePickerController:didFinishPickingMediaWithInfo: is called, you can get the image out of the dictionary passed in using:
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
If you want to retain the image, declare a property with retain for your viewcontroller class, and set it:
self.image = [info valueForKey:UIImagePickerControllerOriginalImage];
精彩评论