Merge pull request #159 from sharathprabhal/simulator-image-timestamp

Add timestamp to simulator still capture
This commit is contained in:
Loch Wansbrough 2016-01-31 18:14:27 -08:00
commit 568ec1e0c7
1 changed files with 18 additions and 3 deletions

View File

@ -401,9 +401,24 @@ RCT_EXPORT_METHOD(hasFlash:(RCTResponseSenderBlock) callback) {
#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);