- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
- />
- <title>
- NativeObj Example
- </title>
- <script type="text/javascript">
- var wc = null,
- bitmap = null;
- // H5 plus事件处理
- function plusReady() {
- wc = plus.webview.currentWebview();
- bitmap = new plus.nativeObj.Bitmap("test");
- // 将webview内容绘制到Bitmap对象中
- wc.draw(bitmap,
- function() {
- console.log('绘制图片成功');
- },
- function(e) {
- console.log('绘制图片失败:' + JSON.stringify(e));
- });
- }
- if (window.plus) {
- plusReady();
- } else {
- document.addEventListener("plusready", plusReady, false);
- }
- // 保存图片
- function saveBitmap() {
- bitmap.save("_doc/a.jpg", {},
- function(i) {
- console.log('保存图片成功:' + JSON.stringify(i));
- },
- function(e) {
- console.log('保存图片失败:' + JSON.stringify(e));
- });
- }
- </script>
- </head>
- <body>
- 保存图片
- <br/>
- <button onclick="saveBitmap()">
- Save
- </button>
- </body>
- </html>
来源: