The sqlite database having text values and image blob it saves the text and (image)blob successfully. Using NSData i saved images in database. The UIImage View should show the respective images depends upon the primary key while retrieving the database records
Code for open the camera and takes the images:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
imagData = UIImagePNGRepresentation(img);
}
Code for Inserting the Image and text values in sqlite:
NSMutableArray *listItemsarr = [[NSMutableArray alloc] init];
if([listItemsarr count]==0){
NSString *insertQry=@"INSERT INTO selection_tbl (expenses_value,category,date,payment,description,image) VALUES(?,?,?,?,?,?)";
sqlite3_stmt *stmt=[DB OpenSQL:[insertQry UTF8String]];
if(stmt !=nil)
{
sqlite3_bind_text(stmt,1, [dataTextfield.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,2, [[selectionarray objectAtIndex:0] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,3, [[selectionarray objectAtIndex:1] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,4, [[selectionarray objectAtIndex:2] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,5, [[selectionarray objectAtIndex:3] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt,6, [imagData bytes], (unsigned)[imagData length], SQLITE_TRANSIENT);
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
[DB CloseSQL];
Aucun commentaire:
Enregistrer un commentaire