1 Star 0 Fork 0

inu1255 / cordova-screenshot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

cordova-screenshot

NPM version

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);

usage in AngularJS

.service('$cordovaScreenshot', ['$q', function ($q){
	return {
		capture: function (filename, extension, quality){
			extension = extension || 'jpg';
			quality = quality || '100';

			var defer = $q.defer();
			
			navigator.screenshot.save(function (error, res){
				if (error) {
					console.error(error);
					defer.reject(error);
				} else {
					console.log('screenshot saved in: ', res.filePath);
					defer.resolve(res.filePath);
				}
			}, extension, quality, filename);
			
			return defer.promise;
		}
	};
}])

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

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/inu1255/cordova-screenshot.git
git@gitee.com:inu1255/cordova-screenshot.git
inu1255
cordova-screenshot
cordova-screenshot
master

搜索帮助