gpt4 book ai didi

ios - UIImagePickerController + 裁剪 : what does allowEditing and what does it not?

转载 作者:技术小花猫 更新时间:2023-10-29 11:06:47 25 4
gpt4 key购买 nike

阅读文档和sample code from apple后关于 UIImagePickerController 并阅读了许多教程甚至 Questions在 Stackoverflow(or here),我得出结论,内置的 UIImagePicker 能够向用户呈现一个“裁剪窗口”,让用户裁剪并移动他想要使用的图像的正确部分。

但是在 iOS 7.1 上检查这些示例,没有出现裁剪窗口。似乎没有什么可以让用户裁剪掉所拍摄图像的一部分。所有测试均在真实硬件(iPhone 5S)上进行,由于缺少摄像头,此处未使用 iPhone 模拟器 ;)

此外,在委托(delegate)方法“didFinishPickingMediaWithInfo”中,“信息”-NSDictionary 中没有“UIImagePickerControllerEditedImage”条目。

我做了什么:

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

#if TARGET_IPHONE_SIMULATOR
// iPhone-Simulator has no camera, just save images to the photoalbum on the simulator to use them here
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif

imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;


[self presentModalViewController:imagePickerController animated:YES];

和委托(delegate)方法:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// .... do something
}

此时,Dictionary 中只有 3 个名为“info”的 Keys 可用:

  • UIImagePickerControllerOriginalImage
  • UIImagePickerControllerMediaMetadata
  • UIImagePickerControllerMediaType

没有别的。此外,没有出现裁剪窗口或任何类似的控件。

我对 ImagePicker 行为的预期有误吗?在此 SF-Question 中,用户写道 "Crop window comes up" .该功能被删除了吗?文档是否过时或我在这里完全错了?

我还尝试了从另一个 answer to a similar question 获取的代码:

- (void)    imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{
// Edited image works great (if you allowed editing)
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}];
}

没有出现裁剪窗口,信息 NSDictionary 中不存在键“UIImagePickerControllerEditedImage”。

有人可以向我解释正确的行为吗?非常感谢您。

最佳答案

这个适合我:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage, *editedImage;

editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];

if (editedImage)
self.profilePictureImageView.image = editedImage;
else
self.profilePictureImageView.image = originalImage;

[picker dismissViewControllerAnimated:YES completion:nil];
}

关于ios - UIImagePickerController + 裁剪 : what does allowEditing and what does it not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24149677/

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