-1

I have this snippet in my ViewDidAppear()

photosImgView.animationImages = [NSArray arrayWithObjects: 
[UIImage imageNamed:@"blueButton.png"],[UIImage imageNamed:@"slider_ball.png"], 
[UIImage imageNamed:@"icon-small-50.png"], nil];

Here the images which are listed should be there in the bundle,its working correct but what i want is instead of taking the images from bundle to photosImgView . I want to take the images which are there in sqlite table with column name PPhotos to photosImgView to animate.

How can i do this any help would be greatly appreciated.

Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
suvarna
  • 697
  • 2
  • 7
  • 10

1 Answers1

0

My suggestions:

  • Never save image in database, because it'll make your database heavy
  • You can save image in document directory and add the path to database
  • If you are using photolibrary image save the asset-url in database

Solution:

You can read the data from database using the select query

- (NSMutableArray *)getImage
{
  NSMutableArray *imageArray = [[NSmutableArray alloc] init];
  if (sqlite3_open([yourDatabasePath UTF8String], &dataBase) == SQLITE_OK)
  {
    NSString *select_sql=[NSString stringWithFormat:@"select PPhotos from imageTable];
    const char *sql = [select_sql UTF8String];
    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
    {
        while(sqlite3_step(selectstmt) == SQLITE_ROW)
        {
            NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 0) length: sqlite3_column_bytes(selectstmt, 0)];           
            [imageArray addObject:[UIImage imageWithData:imageArray]];
        }
    }

  return [imageArray autorelease];
}

Here the getImage will return all the images stored in the database.

Community
  • 1
  • 1
Midhun MP
  • 103,496
  • 31
  • 153
  • 200