I have a camera application in which when I click on the camera button the camera opens and user can take picture from camera or from photo-library.
I have done the came
Now when you opens the camera, you implement the following method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
in the above method add the following code :--
NSData *imageData = UIImageJPEGRepresentation(img, 1);
then call the method of saving data to database.
Make sure you take the field type as blob in database.
Hope it helps.....
You can create a blob type data field in your database and then save the byte data into that column. But it is a bad practice to save images in database. Instead you can save images in documents directory unless it is very necessary to save images in database.
If you are using the UIImagePickerController
, you can get the image in its imagePickerController:didFinishPickingMediaWithInfo:
delegate method. The image you get is an UIImage
object.
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
Now NSData
has a method bytes
which returns void*
. This will point to a C type array which should play well with SQLite.