我使用的代码:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
以下是在图像视图中使用UIImagePickerControllerSourceTypeCamera拍摄图像的功能:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
答案 0 :(得分:2)
试试这个
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
img = [info valueForKey:UIImagePickerControllerEditedImage];
self.imageView.image = img;
NSData *imageData = UIImagePNGRepresentation(img);
这样可行。
答案 1 :(得分:0)
获取图像的NSData
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation(image);
答案 2 :(得分:0)
像这样转换,
NSData *imageData = UIImagePNGRepresentation(image);
如果您想转换回来,
UIImage *image= [UIImage imageWithData:imagedata];