Getting cropped Image from camera in iphone - iphone

I am working on a app where i need to get a image from camera but before that i want to allow cropping of the image. I am using UIImagePickerControllerCropRect in UiImagePicker to get the cropped rectangle. I am able to get the original image from the picker but i am not able to crop it using UIImagePickerControllerCropRect. Can someone help me?
Thanks

this support question is similar http://discussions.apple.com/thread.jspa?threadID=1808549

Try using Below code
Use Below mentioned Delegate Method to get Image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
//you will get image here which is already cropped...
// This will work iOS 3.2 or later
}
Hope this will work for you. Though I haven't tried full code yet But it is giving me scaled Size

Related

Speed up UIImagePickerController by using a low res image then later swapping in the high res image

There is a great wiki about image loading from the camera picker. Which made me aware of costs of taking an image at full resolution.
At the moment, when a photo is picked, I push a new view controller and display the image at full resolution. Pushing the view is a really slow and choppy experience (about 1 fps!) that I want to smooth out. Comparing to picking a photo on Instagram, I notice that they use a low resolution image and later swap in the full image. (I need the full res image because the user should be able to zoom and pan)
The idea I want is somthing like this:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* fullImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// Push a view controller and give it the image.....
}
- (void) viewDidLoad {
CGSize smallerImageSize = _imageView.bounds;
UIImage* smallerImage = [MyHelper quickAndDirtyImageResize:_fullImage
toSize:smallerImageSize];
// Set the low res image for now... then later swap in the high res
_imageView.image = smallerImage;
// Swap in high res image async
// This is the part im unsure about... Im sure UIKit isn't thread-safe!
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, NULL), ^{
_imageView.image = _fullImage;
});
}
I think that UIImage isn't memory mapped in until it is used. Therefore it dons't slow things down until its given to the imageView. Is this correct?
I think image decoding is already done asynchronously by the system, however, it is sill slowing the phone down considerably while its loading.
Is there a way do perform some of the work required to display an image in a very low priority background queue?
You're trying to do things the most complicated way :)
Why not just prepare the small image before pushing the view controller and pass it to them? Look at this code:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *fullImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *smallImage = [fullImage imageScaledToSize:self.view.bounds];
// Push a view controller and give it BOTH images
}
// And in your pushed view controller
- (void)viewDidLoad
{
_imageView.image = self.smallImage;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_imageView.image = self.fullImage;
}
The main thing is that viewDidAppear: will be called right after the animation is done so you can switch images here without any worries.
In addition to Andrey's answer, instead of using imageScaledToSize, use CGImageSourceCreateThumbnailAtIndex. In fact, it's very possible (I am pretty sure it's the case) that any image used in the photo album already has a thumbnail. So instead of bothering with the image itself, grab the existing thumbnail and display it, then use Andrey's code to switch in the main image. This way you do as little work as possible during the animation period.
Calling CGImageSourceCreateThumbnailAtIndex will return the thumbnail image, whether it's already there or needs to be generated. So it'll be quite safe to use, and probably at least as fast as imageScaledToSize.
You can find complete code samples to use it in the Apple docs, no need to duplicate it here.
Have you tried using ALAssetsLibrary to load the thumbnail of that image instead of trying to load the image at full resolution? It's faster than resize it as well.

How to use the picture takes from camera?

Iam developing one application.In that i want to take the picture from camera.For that i used the UIImagePickerControllerSourceTypeCamera.But my problem is how to get that image intomy application.Please tell me how to manage that one.
Thats pretty simple. You have a method in UIImagePickerController which is
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImageWithMediaInfo(NSDictionary *)info. You can get here the image user had selected from UIImagePickerControllerSourceTypeCamera. Now declare an object of UIImage in the header of your AppDelegate. For example I declare UIImage *pickedImage. The purpose to declare this in AppDelegate is that we can use this Image anywhere in our app. Dont retain and synthesize this object. Now come back to your didFinishPickingImage method and now your body of this method should look like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info {
((AppDelegate*)[UIApplication sharedApplication].delegate).pickedImage= [info objectForKey: UIImagePickerControllerOriginalImage];
}
Now you can easily use this image all over your app by just calling ((AppDelegate*)[UIApplication sharedApplication].delegate).pickedImage. Hope it helps.
Happy Coding!

iphone : can't get edited image in uiimagepickercontroller after zooming with type camera

i am pretty stuck in middle of something
i am trying one demo app for UIImagePickerController type camera, and trying to zoom-in/out with camera overlay view using transform scaling matrix.
Well i have done zoom-in/out successfully, but now i want to get captured image in UIimageView, i am getting original image in
- (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info
delegate method but cant get zoomed/scaled edited image into the UIImageView.
So here i have searched lot, but cant get rid of it, i hope you guys will help me out.
your help will be really appreciated.
There are two options:
Retrieve the edited image from the
info dictionary. Key: UIImagePickerControllerEditedImage
If that doesn't work, there is more
info in the dictionary: UIImagePickerControllerCropRect
This is in the delegate method: didFinishPickingMediaWithInfo:(NSDictionary *) info
I assume that you know how to get a image into the imageview.

IPhone - UIImage to Binary String

I have this bit of code that get the image i have picked from the Camera and displays it into a UIImageView. I want to convert the image to a binary string so i can then make a URL call and pass it back to the server. How would I modify this code to get my binary string?
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
You should better pass the NSData got from image jpeg representation to the server by POST method.
Marco
You can find an example of how to do it from Apple in this technote. Not as easy as it should be, but appears that it's the only way to do it. Is it possible for you to get the data before it becomes a UIImage to make your life a little easier? If not, just try the method presented at the link.

UIImageWriteToSavedPhotosAlbum not showing thumbnail in lower left corner

While the following code is saving the image I took from my application into the camera roll. I am trying to figure out how to update the thumbnail image that displays in the left corner next to the take image button when you first launch the camera to be the image that I saved. Shouldn't it always be the last image added to the camera roll? Here is how I am saving it:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *originalImage = [info valueForKey:UIImagePickerControllerOriginalImage];
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(originalImage, nil, nil, nil);
}
}
I'm pretty sure there's nothing you can do to change that thumbnail; it's the Camera app's business what goes in there. At any rate, I think it is defined to contain a thumbnail of the last photo you took using the camera app.
I just tried this:
Launch Camera. Take a photo.
Launch Safari. Save an image from a page.
Launch Camera. The thumbnail is the photo I took, not the saved image.
I say either let it be or file a bug with Apple if you feel the behavior is incorrect.