开发者

Retrieve the UIImage taken with takePicture

开发者 https://www.devze.com 2023-03-09 01:28 出处:网络
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 variab

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消