Add timestamp to simulator still capture

When working with the simulator, its not always obvious if new pics are taken because they are all blank. This PR adds a random color and timestamp to stills captutered on the simulator.
This commit is contained in:
Sharath Prabhal 2016-01-24 06:59:43 -05:00
parent 743685b48a
commit 2d9f768301
1 changed files with 18 additions and 3 deletions

View File

@ -366,9 +366,24 @@ RCT_EXPORT_METHOD(stopCapture) {
#if TARGET_IPHONE_SIMULATOR #if TARGET_IPHONE_SIMULATOR
CGSize size = CGSizeMake(720, 1280); CGSize size = CGSizeMake(720, 1280);
UIGraphicsBeginImageContextWithOptions(size, YES, 0); UIGraphicsBeginImageContextWithOptions(size, YES, 0);
[[UIColor whiteColor] setFill]; // Thanks https://gist.github.com/kylefox/1689973
UIRectFill(CGRectMake(0, 0, size.width, size.height)); CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
[color setFill];
UIRectFill(CGRectMake(0, 0, size.width, size.height));
NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.YY HH:mm:ss"];
NSString *text = [dateFormatter stringFromDate:currentDate];
UIFont *font = [UIFont systemFontOfSize:40.0];
NSDictionary *attributes = [NSDictionary dictionaryWithObjects:
@[font, [UIColor blackColor]]
forKeys:
@[NSFontAttributeName, NSForegroundColorAttributeName]];
[text drawAtPoint:CGPointMake(size.width/3, size.height/2) withAttributes:attributes];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0); NSData *imageData = UIImageJPEGRepresentation(image, 1.0);