|
Ctrl+O 能保存也能读取,如果是Ctrl+I或者是编译后就不能读取图片了,有大神能帮帮忙吗?具体代码如下:
- function domToPic() {
- var wrapper =$(".info");
- var trans = api.require('trans');
- var fs = api.require('fs');
- var wx = api.require('wx');
- var w = $(".info").width();
- var h = $(".info").height();
- var canvas = document.createElement('canvas');
- var context = canvas.getContext('2d');
- var getPixelRatio = function(context) {
- var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
- return (window.devicePixelRatio || 1) / backingStore;
- };
- var ratio = getPixelRatio(context);
- canvas.width = w * ratio;
- canvas.height = h * ratio;
- canvas.style.width = w + 'px';
- canvas.style.height = h + 'px';
- context.scale(ratio, ratio);
- html2canvas(wrapper, {
- canvas : canvas,
- background : '#fff',
- allowTaint : true
- }).then(function(canvas) {
- var imgData = canvas.toDataURL('image/png');
- imgData = imgData.replace('data:image/png;base64,', '');
- trans.saveImage({
- base64Str : imgData,
- album :true,
- imgPath:"fs://img",
- imgName : 'shares001.png',
- }, function(ret, err) {
- alert(JSON.stringify(ret)+'asdfas') //返回true
- fs.getAttribute({
- path: 'fs://img/shares001.png'
- }, function(ret, err) {
- alert(JSON.stringify(ret)+'12111221'); //返回 false
- if (ret.status) {
- } else {
- alert( JSON.stringify( err )+'adfzcc123123' ); //返回文件或文件夹不存在
- }
- });
- });
- });
- }
复制代码
|
|