Skip to content

Instantly share code, notes, and snippets.

@1N50MN14
Created July 8, 2016 16:29
Show Gist options
  • Save 1N50MN14/80562300ec92eab4dfd9f65d819764e1 to your computer and use it in GitHub Desktop.
Save 1N50MN14/80562300ec92eab4dfd9f65d819764e1 to your computer and use it in GitHub Desktop.
takeScreenShot
Date: Wed, 27 Apr 2016 22:12:11 +0500
Subject: [PATCH] Taking screen shot Api
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Usage:
cordova.plugins.iosrtc.takeScreenShot(okResult);
** param ‘okResult’ is a call back method which received base64 PNG
encoded image uri.
**example call back:
function okResult(image){
console.log(image);
}
---
dist/cordova-plugin-iosrtc.js | 8 +++++++-
src/iosrtcPlugin.swift | 8 ++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/dist/cordova-plugin-iosrtc.js b/dist/cordova-plugin-iosrtc.js
index 59f2d7e..11a3852 100644
--- a/dist/cordova-plugin-iosrtc.js
+++ b/dist/cordova-plugin-iosrtc.js
@@ -2216,7 +2216,8 @@ module.exports = {
// Expose the debug module.
debug: require('debug'),
-
+ // Taking screen shot of webview and returning as an image data uri
+ takeScreenShot: takeScreenShot,
// Debug function to see what happens internally.
dump: dump
};
@@ -2228,6 +2229,11 @@ domready(function () {
videoElementsHandler(mediaStreams, mediaStreamRenderers);
});
+ function takeScreenShot(okResult) {
+
+ debug('takeScreenShot');
+ exec(okResult, null, 'iosrtcPlugin', 'takeScreenShot', []);
+};
function refreshVideos() {
debug('refreshVideos()');
diff --git a/src/iosrtcPlugin.swift b/src/iosrtcPlugin.swift
index c932e4f..502e634 100644
--- a/src/iosrtcPlugin.swift
+++ b/src/iosrtcPlugin.swift
@@ -42,6 +42,14 @@ class iosrtcPlugin : CDVPlugin {
)
}
+ func takeScreenShot(command: CDVInvokedUrlCommand){
+ UIGraphicsBeginImageContextWithOptions(self.webView!.bounds.size, true, 0)
+ self.webView!.drawViewHierarchyInRect(self.webView!.bounds, afterScreenUpdates: true)
+ let image = UIGraphicsGetImageFromCurrentImageContext()
+ UIGraphicsEndImageContext()
+ let result:CDVPluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: UIImagePNGRepresentation(image)!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength))
+ self.emit(command.callbackId,result: result);
+ }
override func onReset() {
NSLog("iosrtcPlugin#onReset() | doing nothing")
@SomewhatCloudy
Copy link

Patch doesn't appear to work. It will screenshot the view, but without the video overlay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment