I have 3 UIImageViews for which I want to load an image.
For 1 image this is not a problem, but how do I scale to 3?
The code below is what I have right now.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
[my_image_1 setImage:image forState:UIControlStateNormal];
}
Have you looked at this or this? They seem to be pointing to this resource.
Edit
Based on your comment, I suggest you declare an ivar imageViewToSet in your class and alter your methods in the problem as below,
-(IBAction) getPhoto:(id) sender {
// Add code to identify the sender(button) via tags or outlets and set imageViewToSet to the mapped imageView through a switch or if statement.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageViewToSet.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
Related
I am trying to capture an image and save it in the imageview. Below is the code.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
NSLog(#"Hello");
[picker dismissModalViewControllerAnimated:YES];
[_Image setImage:image];
}
- (IBAction)Capture:(UIButton *)sender {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];
}
The problem is imagepickercontroller is not called at all!! My .h declaration is
#interface AikyaViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
I can get the camera to capture the image, but the image is not saving in my imageview. Infact it is not entering that function itself since its not NSlogging.
Should i have to link anything in the storyboard or any delegates initialisation am i missing?? Plz guide the same.
imagePickerController:didFinishPickingImage:editingInfo: is deprecated
change that method with:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(#"done");
[picker dismissViewControllerAnimated:YES completion:Nil];
[image setImage:[info objectForKey:#"UIImagePickerControllerEditedImage"]];
}
and try to change:
- (IBAction)Capture:(UIButton *)sender {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setDelegate:self];
[cameraUI setAllowsEditing:YES];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];
}
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 have view controller which contains a button which show the image library ,if the user tap the image,the select image will display in the same view with the button ,but i want to show this image in another class ?(view controller).my code is
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
it shows the image in the same view,but my need is to show it in another view.How to dod this.
Store the Image in a UIImage object and pass it to the viewController you want
In your Current View Controller
.h declare the a UIImage object
UIImage *selectedImage;
In .m file
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
selectedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
imageView.image = selectedImage;
}
Pass it to the viewController you want
YourViewController *viewObj = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:[NSBundle mainBundle]];
viewObj.imageToBePassed = selectedImage;
//You should synthesize this object imageToBePassed
[self viewObj animated:YES];
[viewObj release];
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];
I have a uibutton to trigger an iphone's camera to grab an image, and I have a uiimageView in same view to show captured image, but it not showing anything after capturing.
Any solution?
here's my code:
(IBAction)grabImage:(id)sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController: picker animated:YES];
[picker release];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
cameraImageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}