我有一個應用程序,需要一張照片,並把它放在圖像視圖。簡單。 代碼如下所示:用iPhone拍照,然後使用它!
- (void)takePhoto:(id)sender
{
// Lazily allocate image picker controller
if (!imagePickerController) {
imagePickerController = [[UIImagePickerController alloc] init];
// If our device has a camera, we want to take a picture, otherwise, we just pick from
// photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}else
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
// image picker needs a delegate so we can respond to its messages
[imagePickerController setDelegate:self];
}
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
image = [ImageHelpers imageWithImage:image scaledToSize:CGSizeMake(480, 640)];
[imageView setImage:image];
[self dismissModalViewControllerAnimated:YES];
}
當我用相機膠捲一切都很正常,但如果我用實際攝像機的圖像視圖僅僅是黑色的。這是爲什麼?
在圖像視圖中使用它之前,是否需要將它保存到相機膠捲?
設置斷點檢查,如果當它傳遞給ImageHelpers – edo42 2011-04-30 11:51:02
不,它似乎不無圖像是零。我可以使用以下命令將照片保存到相機膠捲:UIImageWriteToSavedPhotosAlbum(),使圖像存在於變量中。當我將它分配給imageView時,它似乎迷失了方向。 – Linus 2011-05-01 12:55:02
我想我必須在將它發送到我的視圖之前將它保存在某處。這裏最好的方法是什麼? – Linus 2011-05-01 13:03:29