0.1.7 • Published 3 years ago
screenshot-plus v0.1.7
cordova-screenshot
The Screenshot plugin allows your application to take screenshots of the current screen and save them into the phone.
how to install
install it via cordova cli
cordova plugin add https://github.com/gitawego/cordova-screenshot.git
notice: in iOS, only jpg format is supported in Android, the default WebView and Crosswalk are both supported
usage
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
});
take screenshot with jpg and custom quality
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
},'jpg',50);
define a filename
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath); //should be path/to/myScreenshot.jpg
}
},'jpg',50,'myScreenShot');
screenshot files are stored in /sdcard/Pictures for android.
take screenshot and get it as Data URI
navigator.screenshot.URI(function(error,res){
if(error){
console.error(error);
}else{
html = '<img style="width:50%;" src="'+res.URI+'">';
document.body.innerHTML = html;
}
},50);
take screen and get it as ArrayBuffer with jpg and custom quality
navigator.screenshot.binary(function(error,res){
if(error){
console.error(error);
}else{
let blob = new Blob([res]) //convert to Blob for http request/response
}
}, 'jpg', 50);
Known Issue
in Android platform I receive the black image with crosswalk
solution:
add this line <preference name="CrosswalkAnimatable" value="true" />
in config.xml, see bug
License
this repo uses the MIT license
0.1.7
3 years ago