index.html
<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title></title> <link href="css/mui.min.css" rel="stylesheet" /> </head> <body> <div> <img src="http://p1.bqimg.com/567571/cedca293f269ba11.jpg" width="100%" /> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> <p>dddd</p> </div> <script src="js/mui.min.js"></script> <script src="js/drawScreen.js"></script> <script type="text/javascript" charset="utf-8"> mui.init(); Mui. PlusReady (function () {/ / screenshot picture proportion and let descWidth = document. The body. The clientWidth; let descHeight = descWidth / (5 / 4); Var options = {successCB: function(e) {return console.log(json.stringify (e))}, errorCB: Function (e) {console.log(json.stringify (e))}, quality: 80, 0~100, default: 50 clip: {// Top: '20px',// for iOS models, the clip top parameter is invalid when bitmap.save, but valid when self.draw. left: '0px', width: descWidth, height: descHeight } } drawScreen(options); }); </script> </body> </html>Copy the code
drawScreen.js
Parameter Description: Parameter name types shows that if the default values will choose successCB | Function | success callback Function | | Y errorCB | Function | fails, the callback Function | Function | fileName | String | File name, do not need to suffix | current timestamp | imgID | String | native photo ID | current timestamp | overwrite | Boolean whether | cover | true | format | String | | PNG saved format | quality | Number | quality of preservation, 1-100, 1, 100 top 50 | | clip | Object | | specified screen area {top: '0px',left: '0px',width: '100%',height: '100%'} */ var drawScreen = function(options) {options = {successCB: options.successCB || function() {}, errorCB: options.errorCB || function() {}, fileName: options.fileName || Date.parse(new Date()), imgID: options.imgID || String(Date.parse(new Date())), overwrite: options.overwrite || true, format: options.format || 'jpg', quality: options.quality || 50, clip: options.clip || { top: '0px', left: '0px', width: '100%', height: '100%' } } var self = plus.webview.currentWebview(); var bitmap = new plus.nativeObj.Bitmap(options.imgID); Self.draw (bitmap, function() {// Save bitmap.save('_doc/' + options.fileName + '.' + options.format, { overwrite: options.overwrite, format: options.format, quality: options.quality, clip: Options. Clip //iOS models, the top parameter of the clip is invalid when bitmap.save, but valid when self.draw. }, function(I) {// Delete Bitmap bitmap.clear(); options.successCB({ success: 'success', details: i.target }); // // Save to system album // plus.gallery. Save (i.target, function(d) {// // destroy Bitmap image // bitmap.clear(); // options.successCB({ // success: 'success', // details: d // }); / /}, function (e) {/ / / / destruction of Bitmap images / / Bitmap. The clear (); // options.errorCB({// error: 'Failed to save image to album ', // details: e //}); / /}); }, function(e) { bitmap.clear(); Options. errorCB({error: 'failed to save image ', details: e}); }); }, function(e) {options.errorcb ({error: 'screen rendering failed ', details: e}); },{clip: options. Clip // When drawing screenshots, set clip to solve the invalid clip-top bug in iOS models}); }Copy the code