We have to let the user open the photo album, pick an image, and edit it .
So using the picker, i can see all the user albums, than when enter an album i can see the images, than, when tapping an image, i get the delegate .
Why i don't see the check sign when choosing an image ? its unclear that you actually pick it. can you also pick more than one, or is it still disabled ?
I can't edit the selected image, after i pick it, i got the delegate called, but i don't have the editing button anywhere .
UIImagePickerController *pickerLibrary = [[UIImagePickerController alloc] init];
pickerLibrary.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerLibrary.delegate = self;
pickerLibrary.editing=YES;
[self presentViewController:pickerLibrary animated:YES completion:nil];
-(void)imagePickerController:
(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
UIImage *imageE = info[UIImagePickerControllerEditedImage];
NSLog(#"%#",image);
NSLog(#"%#",imageE);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Media is a video
}
// Code here to work with media
[self dismissViewControllerAnimated:YES completion:nil];
}
Ok , answer is this :
pickerLibrary.allowsEditing=YES;
and not isEditing
Related
I have a UImage view that opens and you can take a picture with it and view it in the uiimageview. But I added another image view and copied the code and now the image shows up the same image as the second one. I believe it may have something to do with the '[UIImagePickerControllerOriginalImage];'
- (void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
// Get the image and store it in the image view
image = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNail.image = image;
}
- (void)imagePickerControllertwo:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
// Get the image and store it in the image view
imagetwo = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNailtwo.image = imagetwo;
}
Just need a next step, been stuck on this one for quite a while.
There can be only one didFinish-Method. You have to differentiate between what to do inside the method itself. The method already gives you the UIImagePickerController, which is calling the method, so you just have to compare the pointers to it.
- (void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
if(picker == self.pickerController1){
// Get the image and store it in the image view
image = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNail.image = image;
}else if(picker == self.pickerController2){
// Get the image and store it in the image view
imagetwo = info[UIImagePickerControllerOriginalImage];
self.personimgThumbNailtwo.image = imagetwo;
}
}
Edit: You have to have 2 properties defined in the .m file of your class
#property (strong) UIImagePickerController *pickerController1;
#property (strong) UIImagePickerController *pickerController2;
What you have to do now, when instantiating your image-picker is the following
(code taken from the OPs comment under this answer)
- (IBAction)accessPhotoLibrary:(id)sender {
if(!self.pickerController1){
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
self.pickerController1 = imagePicker;
}
[self presentViewController:self.pickerController1 animated:YES completion:nil];
}
I have two UIImageView in the same view.for each imageView I should assign a picture taken from the camera or photos library.
When I start by doing that, I get the same photo for the two imageView.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
imageView2.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
-(IBAction)addPhoto:(id)sender{
UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:#"" delegate:self cancelButtonTitle:#"cancel" destructiveButtonTitle:#"Choose Photo" otherButtonTitles:#"Take Photo ", nil];
[actionSheet showInView:self.view];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
shouldUpdateFirstImage =YES;
// chosenImage = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:nil];
if (shouldUpdateFirstImage) {
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
shouldUpdateFirstImage = NO;
}
else {
pictureView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
shouldUpdateFirstImage = YES;
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Put Picture"])
{
alrtView.hidden = YES;
pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)];
[self.view addSubview:pictureView];
[self addPhoto:self];
}
And the viewController.h
#interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate,UITextViewDelegate>
{
BOOL shouldUpdateFirstImage;
}
The first ImageView is the background.Through an AlertView I choose to add Picture to the first ImageView.After that I recall the same actionsheet to choose the taken photo.
TL;DR you need to track the state of your class, and have your delegate method respond accordingly to that state.
It sounds like you need your class to keep track of how many images have been displayed, and load new selections based on that information. We call this "state", and you have to implement the logic for your imagePickerController delegate method to respond appropriately to that state.
One possible approach would be to have a BOOL scoped to your class (either an ivar or property will do, but ivar is likely more appropriate), then use it's value to keep track of which imageView should be updated.
Assuming you already declared a BOOL named shouldUpdateFirstImage, you could do something like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
if (shouldUpdateFirstImage) {
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
shouldUpdateFirstImage = NO;
}
else {
imageView2.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
shouldUpdateFirstImage = YES;
}
}
This would alternate which imageView was updated with each successive selection.
Try this
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
if(imageView.image)
imageView2.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
else
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
I been stuck on this for a while since it is so weird. I present a user with image picker and on selection use the image as a button background. The problem is that it works only after image is picked for the 2nd time. Do not have to be the same image. Present image picker select picture, nothing. Try again for the same or different picture and everything works just fine. Code is below, does anyone have any suggestions?
-(void) changeProfileImage:(UIImage*) image {
profilePhoto = image;
[editPhotoButton setTitle:#"edit" forState:UIControlStateNormal];
[editPhotoButton setBackgroundImage:profilePhoto forState:UIControlStateNormal];
[editPhotoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) imageInfo {
UIImage* imageToUse;
UIImage* editedTmpImage = [imageInfo objectForKey:#"UIImagePickerControllerEditedImage"];
if (!editedTmpImage)
imageToUse = [imageInfo objectForKey:#"UIImagePickerControllerOriginalImage"];
imageToUse = [imageToUse resizedImageWithContentMode:UIViewContentModeScaleAspectFill bounds:CGSizeMake(MIN(imageToUse.size.width,1024), MIN(imageToUse.size.width, 768)) interpolationQuality:kCGInterpolationHigh];
[self changeProfileImage:imageToUse];
[imagePicker dismissViewControllerAnimated:YES completion:Nil];
}
First, just to make sure, can you just clean it up a little bit like this and try again?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) imageInfo {
UIImage* imageToUse = [imageInfo objectForKey:#"UIImagePickerControllerEditedImage"];
if (!imageToUse) { // this part was confusing above, please use curvy-braces
imageToUse = [imageInfo objectForKey:#"UIImagePickerControllerOriginalImage"];
}
imageToUse = [imageToUse resizedImageWithContentMode:UIViewContentModeScaleAspectFill bounds:CGSizeMake(MIN(imageToUse.size.width,1024), MIN(imageToUse.size.width, 768)) interpolationQuality:kCGInterpolationHigh];
[self changeProfileImage:imageToUse];
[imagePicker dismissViewControllerAnimated:YES completion:nil];
}
This (Is it possible to refresh a single UITableViewCell in a UITableView?) solves the problem! Redrawing sell as recommended in the link works.
Hi all I am new to iOS programming and I am developing an iPad app which uses the iOS built-in camera to take photos and then use the photo taken for image processing (OpenCV) at BACKGROUND. There's no need to show the image process to the user. I would like to process the image once it is taken. But I don't know to how pass the photo just taken (the photo is saved in camera roll and the number(XXXX) of the filename IMG_XXXX.jpg keeps increasing). So how can I retrieve the filename of the photo just taken and pass it to the function for further image processing using OpenCV?
I have used the below two functions to take and save the photo.
// take photo
- (IBAction)captureCamera:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES; // a photo has been taken
}
}
// save photo
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image, self,
#selector(image:finishedSavingWithError:contextInfo:),
nil); }
saveimg = true; // if an image is saved
if (saveimg == true)
{
//imgprocess(); // pass the photo just taken for further image processing
}
saveimg = false; // reset it for next photo-taking
}
Thanks very much for your help!
AssetLibrary can get you the enumeration capability on assets by:
enumerateGroupsWithTypes:usingBlock:failureBlock:
but now you have to try and see if it provides the last object path which is the latest one saved or not.
best of luck
I want it to flow like this I'm doing it tons of times and dosent work.
User pushes the photo button in the app and takes picture.
After taking the picture users has to input detail. sorts options comes out where user can pick 8 different default genre's, and user pushes save.
It goes back to the Home Screen and the User can see the 8 different genre in button & when pushed pictures comes out as a coverflow(flow cover) that is saved in the app. I want to make it work like the above but dosent work.
My Code is until now is:
#implementation ViewController
-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType: UIImagePickerControllerSourceTypeCamera ];
[self presentViewController:picker animated:YES completion:NULL];
}
-(IBAction)ChooseExisting{
picker2 = [[UIImagePickerController alloc]init];
picker2.delegate = self;
[picker2 setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *) info {
image = [info objectForKey:UIImagePickerControllerOriginalImage] ;
[imageview setImage:image];
[self dismissViewControllerAnimated:YES completion:NO];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
#end
#implementation CVCLCoverFlowLayout
-(NSInteger)count {
return [self.collectionView numberOfItemsInSection:0 ];
}
-(CGSize)collectionViewContentSize{
CGSize size = self.collectionView.bounds.size;
size.width = self.count * self.cellInterval;
return size;
}
You are not saving the image you clicked in the delegate function .and when you want to use the saved image then you need to write down the code for same .:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *) info {
image = [info objectForKey:UIImagePickerControllerOriginalImage] ;
[imageview setImage:image];
/ save the image to local storage of your application /
[self dismissViewControllerAnimated:YES completion:NO];
}
You can check the code for same over :
http://dcraziee.wordpress.com/2013/05/20/how-to-save-and-get-image-from-cache-directory/
Please share the blog if you like it.