-5

In my iPad application I want to implement a feature like when a user clicks on a button in the application a screenshot of the current screen should be stored in the database. I'm new to ios development, and I'm totally unaware as how to implement it. Please guide me how.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1531912
  • 363
  • 1
  • 4
  • 18

3 Answers3

1

Refer this link. Here you will find code on how to take screen shot of screen.

Don't save images in database, save your images in Document Directory in iPad. Just save file name of that image in database, which will help you fetch image easily.

Hope this info helps you..

Community
  • 1
  • 1
P.J
  • 6,547
  • 9
  • 44
  • 74
1

try this...

- (UIImage*)captureView:(UIView *)view 
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

- (void)saveScreenshotToPhotosAlbum:(UIView *)view 
{
    appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];  
    UIImageWriteToSavedPhotosAlbum([self captureView:self.view], nil, nil,nil);
}

just send any Uiview you want to capture to - (UIImage*)captureView:(UIView *)view method

P.J.Radadiya
  • 1,493
  • 1
  • 12
  • 21
Rahul Gupta
  • 808
  • 11
  • 15
0

The links in other answers does provide good solutions. As P.J has recommended, it is better to save the image on document directory and save just file name in database is a great approach.

But if at all you are desperate to save the image in database here is the sample that I have used

NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO TABLE_NAME (NAME, IMAGE) VALUES (\"%@\", (?))", name];


 if(sqlite3_prepare_v2(databaseObj,[insertSQL cStringUsingEncoding:NSUTF8StringEncoding], -1, &statement, NULL) == SQLITE_OK)
                {
                    NSData* imageData = UIImagePNGRepresentation(image);
                    sqlite3_bind_blob(statement, 2, [imageData bytes], [imageData length], SQLITE_STATIC);

                if(sqlite3_step(statement) != SQLITE_DONE )
                    NSLog( @"Error: %s", sqlite3_errmsg(databaseObj) );
                else
                    NSLog( @"Insert into row id = %lld", (sqlite3_last_insert_rowid(playerDB)));
                sqlite3_finalize(statement);
            }
Sagrian
  • 1,048
  • 2
  • 11
  • 29
  • Hi, This question has been down voted by 5. Please let me know where it went wrong so that i can correct it. – user1531912 Feb 14 '13 at 08:29
  • @user1531912 : Probably because you did not do any research and posted the answer. Otherwise answer was almost there on the site with some modifications. Not sure though ... – Sagrian Feb 14 '13 at 09:40