gpt4 book ai didi

ios - 如何在 iOS 中将相机拍摄的图像 (UIImagePickerControllerSourceTypeCamera) 转换为 NSData

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:01:12 25 4
gpt4 key购买 nike

我使用的代码:

-(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];
}

以下是在 ImageView 中放置使用 UIImagePickerControllerSourceTypeCamera 拍摄的图像的函数:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

最佳答案

试试这个

UIImage *img          = [info objectForKey:UIImagePickerControllerOriginalImage];
img = [info valueForKey:UIImagePickerControllerEditedImage];
self.imageView.image = img;
NSData *imageData = UIImagePNGRepresentation(img);

这会起作用。

关于ios - 如何在 iOS 中将相机拍摄的图像 (UIImagePickerControllerSourceTypeCamera) 转换为 NSData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28937594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com