I know this question was asked by many people and there are several discussions and arguments on "Why to use sqlite,use FMDB,core data" etc.. to store or insert images in database.But please do understand my problem that I am very much used to sqlite3 and I am unable to go with core data or some other db.Also I am just in learning stages of iphone technology.So I request to please provide me a solution that can be dealt with sqlite only ;)
Apologies if any wrong in my request!
I have a text field that will show table with suggestions when a letter is typed,i.e. from contacts,say if I type letter "L" ,"Lakshaman Rao,Prasanna Lakshmi,"Lokesh Sharan" etc..
Now I am trying to get the corresponding contact picture from the respective contact.So I have searched for code sample on how to retrieve contact images and implemented the following way:
NSData *imgData = nil;
imgData = (NSData *)ABPersonCopyImageData(ref);
contactImage = [UIImage imageWithData:imgData];
Now I have searched for similar kind of questions here and there and the common answer was to save the image in documents directory of the app and in the db save only the path of the image.
As inserting in blobs in db will make our db very very slow :(
But how do I do this.I am unable to understand the code snippet in the links I have gone through properly,how do I convert the contactImage which is of UIImage type to NSString so that,I can insert the string to database table holding a record as VARCHAR type!
EDIT
This is the code suggested there:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
This is code I implemented:
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
NSString *contactFirstName = nil;
NSString *contactLastName = nil;
NSString *fullName = nil;
for ( int i = 0; i < nPeople; i++ )
{
ref = CFArrayGetValueAtIndex( allPeople, i );
contactFirstName = [[[NSString alloc] initWithString:(NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty)]autorelease];
contactLastName = [[[NSString alloc] initWithString:(NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty)]autorelease];
contactLastName = [NSString stringWithFormat:@" %@",contactLastName];
fullName = [contactFirstName stringByAppendingString:contactLastName];
[contactList addObject:fullName];
}
NSData *imgData = nil;
imgData = (NSData *)ABPersonCopyImageData(ref);
contactImage = [UIImage imageWithData:imgData];
CFRelease(allPeople);
CFRelease(addressBook);
Please help me out,Struggling very badly on how to deal and move on with this :(
Thanks all in advance :)