i have the problem with the select the image from UIImagePickerController in ipad in ios 5.
same code was run perfectly in ios 4 .
so what is the problem ?
can any one help me how to use UIImagePickerController in ios 5 ?
Is there any difference between ios 4 and ios 5 for UIImagePickerController ?
Below is the code for the issue.
-(IBAction)selectExitingPicture:(id)sender
{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
[popoverController release];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:CGRectMake(280, 700, 320, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[imagePicker release];
}
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
selectedImageView.image = image;
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
After selecting the image from UIImagePicker in the imagePickerController:didFinishPickingMediaWithInfo method i received the image reference 0*0
Thanks
try this
-(IBAction)buttonpressed{
UIImagePickerController *anImagePickerController = [UIImagePickerController new];
anImagePickerController.delegate = self;
anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *anImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"overlay_320x427.png"]];
anImageView.frame = CGRectMake(0, 1, 320, 427);
anImageView.hidden = YES;
anImagePickerController.cameraOverlayView = anImageView;
[self presentModalViewController:anImagePickerController animated:YES];
[anImagePickerController release];
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:#selector(timerFireMethod:)
userInfo:anImageView
repeats:NO];
[anImageView release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)info {
/* Do something here*/
[self dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
Related
Im using image picker for choose photos from photo library. When i click the button it displays photo library. But when i click particular image it dismiss modalView and image won't load to view.
code:
-(void)showcamera:(id)sender{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
[picker dismissModalViewControllerAnimated:YES];
UIImage *newImage = image;
}
Use this code:
in .h file
{
UIImageView *newImage;
UIImagePickerController *imagePicker;
}
in .m file
- (void)imageTaped:(UITapGestureRecognizer *)tapGesture {
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing =NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//release picker
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//set image
newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
[self.view addSubview:mewImage];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imgPicked = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[imagePickerController dismissModalViewControllerAnimated:YES];
}
}
Declare this in .h
UIImage *imgPicked;
in ViewDidLoad
imgPicked = [[UIImage alloc]init];
Best Way is Add Your Image to UIImageView,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:CGRectMake(#"As U Want")];
ImgView.image = image;
[self.View addSubview: ImgView];
[picker dismissModalViewControllerAnimated:YES];
}
I'm trying to get image from gallery and than display it in UIImageView. My problem is in displaying this image. My code:
- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.popController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
self.popController.delegate = self;
[self.popController presentPopoverFromRect:[fromGalaryButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.popController dismissPopoverAnimated:YES];
self.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self updateDisplay];
}
-(void)updateDisplay {
self.imageView.image = self.image;
self.imageView.hidden = NO;
[self.imageView reloadInputViews];
}
My self.imageView is displaying normally. But there is no any image in. There is my problem?
If you are just picking in image from the gallery then the line of code in didFinishPickingMediaWithInfo method should be:
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
You could also just update the imageView from within the method as such:
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
This is how I did this:
- (void)viewDidLoad {
[super viewDidLoad];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:picker];
}
- (IBAction)getPhoto:(id)sender {
if(sender == choosePhotoButton) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[imagePickerPopover presentPopoverFromBarButtonItem:choosePhotoButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[imagePickerPopover dismissPopoverAnimated:YES];
imageViewer.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
I'm trying to present an UIImagePickerController. It works fine on simulator, but after few times of presenting, I get an error in the console.
More than maximum 5 filtered album lists trying to register.
This will fail.
Here is the code:
- (IBAction)imageSelectorPressed:(id)sender
{
UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
// Set source to the Photo Library
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.imagePopOverController = popover;
[self.imagePopOverController setDelegate:self];
[self.imagePopOverController presentPopoverFromRect:[kepekBtn frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popover release];
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
[popoverController dismissPopoverAnimated:YES];
[self setImagePopOverController:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.imagePopOverController dismissPopoverAnimated:NO];
[image setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
picker = nil;
[self setImagePopOverController:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.imagePopOverController dismissPopoverAnimated:NO];
picker = nil;
[self setImagePopOverController:nil];
}
UPDATE: I've checked the contact app on the iPad. Edited a person, and it has a same error in the console log. BUT it is not crashing, while my app is. So the proper question: How can I fix it?
I have implemented picture taking while pressing UI Button butwhen ever i pressed the button got app crashed.
Here is the source code.
.h file
#interface Camera : UIViewController
<UIImagePickerControllerDelegate>
{
UIImagePickerController *mPicture;
}
#property (nonatomic, retain) UIImagePickerController *mPicture;
.m file
#implementaion Camera
#synthesize mPicture;
-(void)pictureButtonPushed
{
UIImagePickerControllerSourceType mType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:mType])
{
mPicture.sourceType = mType;
[self presentModalViewController:mPicture animated:YES];
}
}
Thanks in advance
Try this one
Hope it will help :)
-(IBAction)takePhoto
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}
// image picker needs a delegate,
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
-(IBAction)chooseFromLibrary
{
UIImagePickerController *imagePickerController= [[UIImagePickerController alloc]init];
[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];
}
//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[myImageView setImage:image]; // "myImageView" name of any UImageView.
}
Here is the code for what you want
- (void)cameraPressed
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle:#"Set a Prifile Picture"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Choose From Library",#"Take a New Photo",nil];
[menu showInView:[self.navigationController view] ];
}
// actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
#try {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
else {
[appDelegate showAlertWithTitle:#"Info" message:#"This function needs a camera which is only available on the iPhone or iPod."];
}
}
#catch (NSException *e) {
}
}
if (buttonIndex == 0) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//flag = TRUE;
[self dismissModalViewControllerAnimated:YES];
//[appDelegate showLoadingView];
UIImage *capturedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
Use this image object where ever you want to use.
I have to add an image in a tweet. I tried this code, and only the picker shows. When I tap on the image it doesn't grab... Here is the code:
- (IBAction)sendImageTweet:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
[tweetViewController addImage:(UIImage *)image];
[self presentModalViewController:tweetViewController animated:YES];
}
Thanks, and sorry for my English...
I think the problem is you are dismissing a viewController and presenting one at the same time. I did this
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[self performSelector: #selector(showTweetwithPhoto:) withObject: image afterDelay: 0.5];
}
and it worked perfectly
-(void) showTweetwithPhoto:(UIImage*)image {
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController addImage:image];
[self presentModalViewController:tweetViewController animated:YES];
}
Try casting the image data (returned by UIImagePickerController) to UIImage object, as shown below. (I have changed 2nd line of your code).
UIImage *image = (UIImage*)[info objectForKey:#"UIImagePickerControllerOriginalImage"];
UIImage * image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];