Library photos as source to UIImage - iphone

How to give images in photo library and camera as source to UIImage
/* On button click i want to save image */
myImage = /*What i have to give here to take camera or library images*/
UIImageWriteToSavedPhotosAlbum(myImage, self,
#selector(image:didFinishSavingWithError:contextInfo:), nil);

You need to use the UIImagePickerController object. It will present the modal view that allows either taking a picture or selecting an image from the device library. You should also become familiar with the UIImagePickerControllerDelegate protocol. With these two, it is easy to interact with both the camera and on-device library.

Related

What are the methods/classes I need to create an iPhone upload photo form?

Currently I have a view with an ImageViewer and 2 buttons (Browse & Upload). I'm currently searching for methods to display the iPhone photo album once the button is pressed.
I've looked at this example here but I assume this one is the method you call when you want to upload the photo into the server.
Objective C: How to upload image and text using HTTP POST?
I'd like to duplicate the functionality of a web upload form.
1. Click button to browse folders.
2. Choose photo and display in a container.
3. Click Upload to upload photo into the server.
**Update:
Found some nice tutorials that helped me start with my iPhone app photo upload form.
Using UIImagePickerController
http://iosdevelopertips.com/camera/camera-application-to-take-pictures-and-save-images-to-photo-album.html
http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/
Adding images to iPhone Simulator
You will have to use UIImagePickerController class
Here is the class reference for UIImagePickerController
Initialize the picker controller in your button event handler method.
Then set the UIImagePickerControllerDelegate to your current viewController
Here is the class reference for UIImagePickerControllerDelegate
picker.delegate = self;
Set the UIImagePickerControllerSourceType of picker to UIImagePickerControllerSourceTypePhotoLibrary
picker.UIImagePickerControllerSourceType = UIImagePickerControllerSourceTypePhotoLibrary
Then present the pickerViewController (if your target device is an iPad, present the imagePickerView in a popOver control)
Once user selects an image picker controller will automatically call its delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
You can get the selected image by accessing the value for UIImagePickerControllerOriginalImage from the NSDictionary *info
Then you can use the image for uploading to server as mentioned in the post link
These are some tutorials for UIImagePickerController
Tutorial one
Tutorial two
Tutorial three
for getting images from iPhone library you have to use UIImagePickerController.
m_imagePickerController = [[UIImagePickerController alloc] init];
m_imagePickerController.delegate = self;
m_imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
hope this will help you

Must I save the captured image to the Camera Roll when using UIImagePickerController with source type camera?

From the docs of UIImagePickerController:
When the user taps a button to pick a newly-captured or saved image or
movie, or cancels the operation, dismiss the image picker using your
delegate object. For newly-captured media, your delegate can then save
it to the Camera Roll on the device. For previously-saved media, your
delegate can then use the image data according to the purpose of your
app.
So this reads like I MUST save the captured image to the Camera Roll. Is this true? Reason for rejection if not done?
No, you do not need to save to Camera roll when UIImagePickerController is dismissed. I have done this in several apps.

UIImagePickerControllerSourceTypeCamera crashes in IPHONE Simulator?

Is it a known issue that if you try to test your UIImagePickerController using the Camera as a source type then the simulator will crash?
I have the following code:
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
[self.imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.imgPicker animated:YES];
[imgPicker release];
Running this in simulator, I get an objc-exception-throw error on the stack # -[UIImagePickerController setSourceType:].
Now if I set the source type to the Photo Library though, everything runs smoothly and fine? What's the deal?
Simulator doesn't have the camera and can't simulate to take a picture (it would have been nice to use the isight but Apple has not been so kindly). However Your code is not safe because, for example, old ipod touch doesn't have a camera and in this case your app will crash on this device.
As Apple suggest in UIImagePickerController documentation:
To use an image picker controller
containing its default controls,
perform these steps:
1.Verify that the device is capable of picking content from the
desired source. Do this calling the
isSourceTypeAvailable: class method,
providing a constant from the
“UIImagePickerControllerSourceType”
enum.
2.Check which media types are available, for the source type you’re
using, by calling the
availableMediaTypesForSourceType:
class method. This lets you
distinguish between a camera that can
be used for video recording and one
that can be used only for still
images.
3.Tell the image picker controller to adjust the UI according to the
media types you want to make
available—still images, movies, or
both—by setting the mediaTypes
property.
4.Present the user interface by calling the
presentModalViewController:animated:
method of the currently active view
controller, passing your configured
image picker controller as the new
view controller.
5.When the user taps a button to pick a newly-captured or saved image
or movie, or cancels the operation,
dismiss the image picker using your
delegate object. For newly-captured
media, your delegate can then save it
to the Camera Roll on the device. For
previously-saved media, your delegate
can then use the image data according
to the purpose of your app.
So you have to call isSourceTypeAvailable and set your sourceType consistently.

grab image displayed on the UIImagePickerController without the overlay

I'm using UIImagePickerController with the camera as the sourceType. I am also drawing a custom overlay on the picker using the built-in overlay functionality(picker.overlay = myOverlay).
How can I get an UIImage of the camera, excluding my overlay?. I tried using UIGetScreenImage() but that captures my overlay as well.
[picker takePicture];

Merging photos - iPhone SDK

I am making an app that adds a picture frame to a photo.
I would like to know how to have my Save button save both Images (the photo, and the frame) as one Image.
Right now it only saves one of the images.
In interface builder I have the save action saving the image that is loaded into an ImageView, with the frame ImageView overlaying that image.
I'd like to merge the two photos as one, so the save action can save the image with the frame.
Thanks!
If you've displayed the frame over the photo in your UI, just use UIScreenGetImage something like
...
CGImageRef screen = UIGetScreenImage();
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
// You could, e.g., save the captured image to photo album
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
This probably isn't what you want, but if you load both images into OpenGL (there's a nice Apple sample that loads images in OpenGL), lay one on top of the other, and then write the result to an image (excellent tutorial here - http://www.bit-101.com/blog/?p=1861).
You don't even need to render it to the screen, so there's no fiddling around with EAGL.