calling "- (void) takePicture" returns non-foucsed image - ios

I have an UIImagePickerController with my own camera overlay. In that overlay I have a button that the user can press to take a photo.
Currently, I have an IBAction on "Touch Up Inside" that will take a picture. self.imagePickerController is my reference to UIImagePickerController
- (IBAction)onSnapClicked:(id)sender {
[self.imagePickerController takePicture];
}
My problem is that, in the callback method. The image that I get back is always blurry. Please help
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the original image
UIImage *originalImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}

They are the same quality. You might have created a lag somewhere thus gives you the false sense of finish taking picture, while it is actually capturing.
Unless your button allows touch through. In that case, the camera always try to focus that part of your picture. You have to prevent that from happening. How to do that, look into my answer on this question : Exlusive touch in cameraoverlay view (of the camerapicker) in iOS?

Related

How To implement double exposure for picking images?

In my app I'm having two imageviews, first imageview will be constant and for second imageview ,after picking image it will zoom and it can be place any where in the view and second image will be merged with first image and after merging second imageview will be nil and first imageview will be having two images and we can pic as many images in second imageview and can move anywhere but we need pic only single image at single time.How to implement this.?.Thanks in advance.
A simple image usually has 32bit of color information per pixel (rgb: ff ff ff), a grayscale image has 8bit.
It should be obvious that a conversion from 32bit to 8bit is not reversible.
To achieve your goal you have to keep a copy of your original Image.
When you select Image from gallery save it in one UIImage object as original image before applying any grayscale on that.
Make another copy of selected Image and apply grayscale on that and assign this image to ImageView.
Now when you touch on this ImageView (Detect touch using Gestures) set originalImage to the ImageView.
Edit:
You can have function like this:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
// Edited image works great (if you allowed editing)
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
}
In above code you can declare both editedImage and originalImage variables at global scope, assign editedImage as image for your ImageView and on touch on ImageView you can show originalImage

App Crashing when taking picture on device - uipickercontroller

I have seen this question being asked many times before but I can't seem to get an answer that helps me. So here is my situation :
I have a user press a button that asks them if they want to take a picture or choose one from their album. When testing on my actual phone the choosing from album mode works, but the picture from camera goes all weird.
What happens : User is shown camera view -> user takes picture -> CRASH
The crash is not one in the console tho... I get a window on top of my xCode window saying :
App stopped unexpectedly due to Memory Pressure.
So I read that I need to resize the image I am getting from the camera before I display a small thumbnail for the user... I am doing that but to no avail... this has now become a consistent issue.
Here is my code :
(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:nil];
//UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
CGRect rect = CGRectMake(0,0,320,480);
UIGraphicsBeginImageContext(rect.size);
//[img drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_photoTaken setImage:picture1];
[self updateAppropriateCharacterCount];
[_userInputTextField becomeFirstResponder];
}
Let me explain what the variables are :
_photoTaken is a pointer to a UIImageView where I want to display the thumbnail. It is much smaller than 320 x 480 though.
Now I also have this method :
(void) takePhotoButtonPressed {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
Finally before I did all this funny resize stuff I was setting the "img" variable to another pointer called "image" that was defined in my local implantation. I was using this to check (later in the code) if an image existed.
Any help would be appreciated, or some guidance.
Thank you much
EDIT
I also noticed that if I run my app for some time before going right to taking a picture it crashes before even showing the camera - I press take a photo and bam dead....
I have a project designed to be more memory efficient for taking pictures. The files will be larger than thumbnail, but it usually runs much lighter than UIImagePicker, and the final picture files are significantly smaller.
You can find it here

iOS UIImagePickerController annoying rotation (display picture) issue

I'm writing app now which is using uiimagepicturecontroller.
Task is very simply. U need to take a picture a thing inside place in overlay (overlay is just a circle) and then display it. It works fine, when user holding the iPhone vertical. Picture is cropping and displaying fine. Problem is when user rotate their iPhone horizontal. I suppose camera is rotating and i can't display photo as i'd like.
Any ideas how to remove autorotatin?
Device orientations in my target->general is only Portrait
I tried override autorotate method in UIImagePickerController and it didn't works
Any idea how to fix it? Or any tricky tricky method to display image correctly?
Best regards,
David.
EDIT: Solution for this is use AVCam and write "own" class to take a picture.
i think it works:
-(void)imagePickerController:(UIImagePickerController *)pickerinput didFinishPickingMediaWithInfo:(NSDictionary *)info {
[pickerinput dismissViewControllerAnimated:YES completion:nil];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *yourImgView=[[UIImageView alloc] initwithimage:image];
//please add this
yourImgView.transform = CGAffineTransformMakeRotation(M_PI/2);
}
Try this.
_img = [UIImage imageWithCIImage:_image scale:_imgScale orientation:_imgOrient];
_imgOrient = _img.imageOrientation;
_imgScale = _img.scale;

UIImageView does not show Image from UIImagePickerController

I am trying to take a picture with my app and then show it in a UIImageView that is predefined in my .xib. I have a IBOutlet UIImageView *_foto that is linked to the UIImageView in the .xib
When I do the following the picture doesnt show in the UIImageView after taking a picture:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
_foto.image = image;
//Also tried set image, and resizing the image first
[self dismissModalViewControllerAnimated:YES];
}
Now, when I add code to create a new image view with the image returned from my picker, and add that as a subView to my view like this, something strange happens:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
UIImageView *iv = [ [UIImageView alloc] initWithImage:image];
[self.view addSubview:iv];
[iv release];
_foto.image = image;
[self dismissModalViewControllerAnimated:YES];
}
Now the image shows in both the newly created image view in the left top corner of my view,as expected, but also in my _foto UIImageView. This has me seriously confused, and I have no idea what is going on, all i know is that it is not the behavior i expected. Does anyone have any clue, and hopefully a proper solution for this problem?
Artur Ozierański's answer is partially correct.
If you're using viewDidLayoutSubviews() to configure your layout, this gets called when the picker disappears, so if you're setting the default image in viewDidLayoutSubviews(), you'll reset back to the default image.
Configure the default image in viewDidLoad.
UIImagePickerController grab a lot of device memory while picking an image. During - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo I've noticed many times memory warnings level 1 and 2. It may cause force unload and reload your view, launch viewDidLoad method of your view controller again. If your _foto object is an IBOutlet it will be removed from memory and load again with start values of all properties (image too). Also if you set image to nil in viewDidLoad it may be a reason.
Put some NSLog into viewDidLoad to check out if it is relaunched. Also you may try to put captured image into library - if image exists in library the problem probably is in view unloading.

For iPad Developers: How to view an image selected from photo library’s popover in a UIImageView, iPad

I am working on an application for iPad, it is working fine until i reached this point:
The app shows the popover for the photo library, but when I choose the photo, the popover doesn't hide, and I also want it to view the selected image in a UIImageView, however i do not know how.
I am sure there is something wrong in the didFinishpickingMediaWithInfo function. here is the function's code:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishpickingMediaWithInfo:(NSDictionary *)info{
//bgImage is a UIImageView
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Dismiss UIImagePickerController and release it [picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
}
My first question is: What am I supposed to add to this function for viewing the selected photo in the UIImageView? (When I click on the photo from the photo library in the simulator, neither the photo library hide nor the image is viewed in the specified UIImageView)
2- I have read that I should've used UIImage instead of UIImageView.. Is this true? If yes, what about the interface builder? There is nothing called UIImage?
To close the image picker, use:
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
What you get from
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
is not an UIImageView, it's a UIImage. To get it displayed, you need to have a UIImageView in your UI somewhere, and set the view's image with what you just got from the picker:
imageView.image = bgImage
Hope this helps

Resources