我已经设置了一些功能。但我迷失在哪里。一旦我知道如何实际使用图像,我就可以弄清楚如何处理facebook。我尝试将图像保存到NSDictionary中,然后重定向到另一个View Controller,但它不会让我从imagePickerController方法中重定向。所以任何人都知道如何使用从相机胶卷中选择的图像?
我的下一个想法是将它保存在NSDictionary中,然后只需要一个语句检查NSdictionary值是否发生了变化,但这根本不是一种有效的方法。
以下编辑包括提供的答案,但没有任何反应,没有图像显示或任何东西。我错过了什么?
- (void) useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
newMedia = NO;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"image:%@",image);
displayPhoto.image = image;
[displayPhoto setFrame:CGRectMake(0, 0, 320, 480)];
[[self view] addSubview:displayPhoto];
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
答案 0 :(得分:1)
假设您已经使用已创建的按钮从视图控制器调用此项,为什么不在视图控制器上添加UIImageView?将其称为myPhotoImageView或类似的东西,然后在didFinishPickingMediaWithInfo方法中,只需在
之后添加以下代码行:UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
as
myPhotoImageView.image = image;
要调整图像视图的大小以使方面看起来很好。
CGSize size = image.size;
CGRect photoFrame;
if (size.width > size.height)
{
// Landscape
CGFloat scaleFactor = 320 / size.width;
photoFrame = CGRectMake(0, 0, 320, size.height*scaleFactor);
}
else
{
// Portrait
CGFloat scaleFactor = 320 / size.height;
photoFrame = CGRectMake(0, 0, size.width*scaleFactor, 320);
}
myPhotoImageView.frame = photoFrame;