移动端截屏
时间隔得久远了,忘记是哪位大佬的了,再次感谢。
参数具体格式查看方法内。成功函数为必填。function successCB()
var save = function(successCB, errorCB, fileName, imgID, overwrite, format, quality, clip) {
errorCB = errorCB || function() {};
fileName = fileName || Date.parse(new Date());
imgID = imgID || String(Date.parse(new Date()));
overwrite = overwrite || true;
format = format || ‘png‘;
quality = quality || 100;
clip = clip || {
top: ‘9%‘,
left: ‘0px‘,
width: ‘100%‘,
height: ‘90%‘
};
var self = plus.webview.currentWebview();
var bitmap = new plus.nativeObj.Bitmap(imgID);
//绘制截图
self.draw(bitmap, function() {
// 保存Bitmap图片
bitmap.save(‘_doc/‘ + fileName + ‘.‘ + format, {
overwrite: overwrite,
format: format,
quality: quality,
clip: clip
}, function(i) {
//保存到系统相册
plus.gallery.save(i.target, function(d) {
//销毁Bitmap图片
bitmap.clear();
success({
success: ‘success‘,
details: d
});
plus.io.resolveLocalFileSystemURL(d function(entry) {
UpladFile(entry);
}, function(e) {
console.log(‘读取影像材料失败!‘);
});
}, function(e) {
//销毁Bitmap图片
bitmap.clear();
errorCB({
error: ‘图片保存至相册失败‘,
details: e
});
});
}, function(e) {
bitmap.clear();
errorCB({
error: ‘图片保存失败‘,
details: e
});
});
}, function(e) {
errorCB({
error: ‘截屏绘制失败‘,
details: e
});
});
}