我用我的UIImagePickerController
委托下面的代码:的UIImage不从摄像头显示,刚刚从照片库
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];
[self.personPhotoButton setBackgroundImage:image forState:UIControlStateNormal];
[self dismissModalViewControllerAnimated:YES];
}
它完美如果图像是从用户的照片库,但如果它来自相机,没有图像出现在按钮中。没有任何错误或崩溃,它只是不起作用(按钮背景保持不变)。当我在info
上使用NSLog
时,它显示UIImagePickerControllerOriginalImage
中有一个图像对象,但它不会显示。我尝试调整它的大小,但这并没有改变任何东西。
有什么想法?
编辑:我能八九不离十得到它的工作通过添加下面的上述方法:
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
然后,我有这样的方法:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
[self.personPhotoButton setBackgroundImage:image forState:UIControlStateNormal];
}
所以,是否需要保存照片才能显示?除非明确保存到相册中,否则我不能显示UIImage吗?理想情况下,我宁愿不必这样做,但似乎这是我可能必须走的路线。我也会尝试将它保存到磁盘(而不是照片库),也许这将工作。
是的,我试过,没有骰子:( – 2011-02-25 02:12:54