Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will show you how to <a href="http://www.iphonesdkarticles.com/2009/02/sqlite-tutorial-saving-images-in.html" rel="nofollow">Saving image in the SQLite database</a></p> <p>Is there any specific reason to store entire image into database?</p> <p>I would like to suggest you to store image in an application's Documents/Caches folder and only location including image name will be store into your database as varchar, instead of storing the whole image into database. So that when next time you need to use image, you just have to follow the paths those have been store for an individual image. Thus, application also doesn't has to bother to redraw images repeatedly and that will improve your application's performance too.</p> <p>Below is sample code for practice..</p> <pre> - (void)saveImage:(UIImage *)image forPerson:(NSString *)fullName { // Make file name first NSString *filename = [fullName stringByAppendingString:@".png"]; // or .jpg // Get the path of the app documents directory NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Append the filename and get the full image path NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:filename]; // Now convert the image to PNG/JPEG and write it to the image path NSData *imageData = UIImagePNGRepresentation(image); [imageData writeToFile:savedImagePath atomically:NO]; // Here you save the savedImagePath to your DB ... } </pre> <p>To get image back and display...</p> <pre> - (UIImage *)loadImage:(NSString *)filePath { return [UIImage imageWithContentsOfFile:filePath]; } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload