Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Device.saveScreenshot

  • Loading branch information...
commit 2aa71cf15d1a51a0f4ebb742603034e8dd3b3101 1 parent cd5a9cc
Michael Nachbaur authored
View
1  iphone/Classes/Device.h
@@ -15,5 +15,6 @@
- (NSDictionary*) deviceProperties;
- (void) hideSplashScreen:(NSMutableArray*) arguments withDict:(NSMutableDictionary*) options;
+- (void)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options;
@end
View
19 iphone/Classes/Device.m
@@ -42,4 +42,23 @@ - (void) hideSplashScreen:(NSMutableArray*) arguments withDict:(NSMutableDiction
[[[self appDelegate] window] bringSubviewToFront:[self appViewController].view];
}
+/**
+ Save the web view as a screenshot. Currently only supports saving to the photo library.
+ */
+- (void)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options
+{
+ CGRect screenRect = [[UIScreen mainScreen] bounds];
+ UIGraphicsBeginImageContext(screenRect.size);
+
+ CGContextRef ctx = UIGraphicsGetCurrentContext();
+ [[UIColor blackColor] set];
+ CGContextFillRect(ctx, screenRect);
+
+ [webView.layer renderInContext:ctx];
+
+ UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
+ UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
+ UIGraphicsEndImageContext();
+}
+
@end
View
5 javascripts/device.js
@@ -35,6 +35,11 @@ function Device() {
*/
Device.prototype.hideSplashScreen = function() {};
+/**
+ * Save the current state of the webview object as a screenshot.
+ */
+Device.prototype.saveScreenshot = function() {};
+
PhoneGap.addConstructor(function() {
navigator.device = window.device = new Device();
});
View
3  javascripts/iphone/device.js
@@ -1,3 +1,6 @@
Device.prototype.hideSplashScreen = function() {
PhoneGap.exec('Device.hideSplashScreen');
};
+Device.prototype.saveScreenshot = function() {
+ PhoneGap.exec('Device.saveScreenshot');
+};
Please sign in to comment.
Something went wrong with that request. Please try again.