How to take a picture and save in SQLite database on iOS

后端 未结 3 923
小蘑菇
小蘑菇 2021-02-06 19:33

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

相关标签:
3条回答
  • 2021-02-06 19:55

    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.....

    0 讨论(0)
  • 2021-02-06 19:57

    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.

    0 讨论(0)
  • 2021-02-06 20:00

    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.

    0 讨论(0)
提交回复
热议问题