Ionic dom-to-image 插件在渲染时崩溃
Ionic dom-to-image plugin crash when rendering
我无法显示任何代码,因为问题不是给我错误、消息或任何东西。
我遇到这样的情况:
我的应用程序必须使用 domToImage.
进行 2 次渲染
首先,我从 Camera/Gallery (base64) 中获取图像
然后添加到 img.src 它呈现一个简单的背景。
我将这个 bg 放在一组 Dom 元素下,然后将它们一起渲染
这个过程进行得很顺利,没有问题,没有错误,没有错误。
直到突然间它开始使应用程序崩溃。我根本没有对我的代码进行任何更新,任何更改。一直在用,然后就不行了。
我重新制作了流程并缩小到仅在渲染时。仍然崩溃。
没有行动模式。它在 bg 渲染或设置渲染下崩溃,或者有时不崩溃。但它不会连续错过 2 个。如果第一个例程没有失败,第二个例程将失败。任何地方。
我迷路了...
添加的 Xwalk,删除,从地面创建另一个相同的项目,仍然崩溃。
更改了插件导入,甚至为某个全新安装重置了 smartphone...
不是我 phone 的问题,因为世界各地的许多客户都在报告这个错误。
有什么方向吗?
使用 Dom-to-Image 2.6.0
Ionic 3 - Android 平台
索姆代码:
home.ts
import domtoimage from "dom-to-image";
var node= document.getElementById("render");
domtoimage.toPng(node, {
height: node.offsetHeight * 2,
width: node.offsetWidth * 2)
})
.then(dataUrl => {
EventEmitterService.get("fullRendered").emit(dataUrl);
})
.catch(error => {
alert(error)
});
=================================
package.json
{
"name": "Ionic App",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/admob-free": "^4.18.0",
"@ionic-native/android-full-screen": "^4.18.0",
"@ionic-native/app-version": "^4.18.0",
"@ionic-native/camera": "^4.18.0",
"@ionic-native/core": "~4.17.0",
"@ionic-native/file": "^4.18.0",
"@ionic-native/photo-library": "^4.18.0",
"@ionic-native/splash-screen": "~4.17.0",
"@ionic-native/status-bar": "~4.17.0",
"@ionic/storage": "^2.2.0",
"angular2-uuid": "^1.1.1",
"cordova-admob-sdk": "^0.21.0",
"cordova-android": "^7.0.0",
"cordova-plugin-admob-free": "0.24.0",
"cordova-plugin-app-version": "0.1.9",
"cordova-plugin-camera": "4.0.3",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "6.0.1",
"cordova-plugin-fullscreen": "1.2.0",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.3.1",
"cordova-plugin-photo-library": "2.2.0",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-promise-polyfill": "0.0.2",
"cordova-sqlite-storage": "2.5.2",
"dom-to-image": "^2.6.0",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"jquery": "^3.3.1",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.1",
"@types/jquery": "^3.3.24",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-fullscreen": {},
"cordova-plugin-file": {},
"cordova-plugin-app-version": {},
"cordova-plugin-camera": {},
"cordova-plugin-photo-library": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "Save images on your phone"
},
"cordova-sqlite-storage": {},
"cordova-plugin-admob-free": {
"ADMOB_APP_ID": ""
},
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-ionic-keyboard": {}
},
"platforms": [
"android"
]
}
}
我建议你可以尝试用另一个Js包来达到这个目的。让我们试试 html2canvas :
安装
npm install --save html2canvas
导入
import html2canvas from 'html2canvas';
用法
var element = document.getElementById('div-to-render');
html2canvas(element, { allowTaint : true }).then((canvas) =>
{
canvas.getContext('2d');
var image = canvas.toDataURL('image/jpeg', 1.0);
});
现在您可以按照此处的说明显示或下载图像:
我无法显示任何代码,因为问题不是给我错误、消息或任何东西。
我遇到这样的情况: 我的应用程序必须使用 domToImage.
进行 2 次渲染首先,我从 Camera/Gallery (base64) 中获取图像 然后添加到 img.src 它呈现一个简单的背景。 我将这个 bg 放在一组 Dom 元素下,然后将它们一起渲染 这个过程进行得很顺利,没有问题,没有错误,没有错误。
直到突然间它开始使应用程序崩溃。我根本没有对我的代码进行任何更新,任何更改。一直在用,然后就不行了。
我重新制作了流程并缩小到仅在渲染时。仍然崩溃。
没有行动模式。它在 bg 渲染或设置渲染下崩溃,或者有时不崩溃。但它不会连续错过 2 个。如果第一个例程没有失败,第二个例程将失败。任何地方。
我迷路了... 添加的 Xwalk,删除,从地面创建另一个相同的项目,仍然崩溃。 更改了插件导入,甚至为某个全新安装重置了 smartphone... 不是我 phone 的问题,因为世界各地的许多客户都在报告这个错误。
有什么方向吗?
使用 Dom-to-Image 2.6.0
Ionic 3 - Android 平台
索姆代码:
home.ts
import domtoimage from "dom-to-image";
var node= document.getElementById("render");
domtoimage.toPng(node, {
height: node.offsetHeight * 2,
width: node.offsetWidth * 2)
})
.then(dataUrl => {
EventEmitterService.get("fullRendered").emit(dataUrl);
})
.catch(error => {
alert(error)
});
=================================
package.json
{
"name": "Ionic App",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/admob-free": "^4.18.0",
"@ionic-native/android-full-screen": "^4.18.0",
"@ionic-native/app-version": "^4.18.0",
"@ionic-native/camera": "^4.18.0",
"@ionic-native/core": "~4.17.0",
"@ionic-native/file": "^4.18.0",
"@ionic-native/photo-library": "^4.18.0",
"@ionic-native/splash-screen": "~4.17.0",
"@ionic-native/status-bar": "~4.17.0",
"@ionic/storage": "^2.2.0",
"angular2-uuid": "^1.1.1",
"cordova-admob-sdk": "^0.21.0",
"cordova-android": "^7.0.0",
"cordova-plugin-admob-free": "0.24.0",
"cordova-plugin-app-version": "0.1.9",
"cordova-plugin-camera": "4.0.3",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "6.0.1",
"cordova-plugin-fullscreen": "1.2.0",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.3.1",
"cordova-plugin-photo-library": "2.2.0",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-promise-polyfill": "0.0.2",
"cordova-sqlite-storage": "2.5.2",
"dom-to-image": "^2.6.0",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"jquery": "^3.3.1",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.1",
"@types/jquery": "^3.3.24",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-fullscreen": {},
"cordova-plugin-file": {},
"cordova-plugin-app-version": {},
"cordova-plugin-camera": {},
"cordova-plugin-photo-library": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "Save images on your phone"
},
"cordova-sqlite-storage": {},
"cordova-plugin-admob-free": {
"ADMOB_APP_ID": ""
},
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-ionic-keyboard": {}
},
"platforms": [
"android"
]
}
}
我建议你可以尝试用另一个Js包来达到这个目的。让我们试试 html2canvas :
安装
npm install --save html2canvas
导入
import html2canvas from 'html2canvas';
用法
var element = document.getElementById('div-to-render');
html2canvas(element, { allowTaint : true }).then((canvas) =>
{
canvas.getContext('2d');
var image = canvas.toDataURL('image/jpeg', 1.0);
});
现在您可以按照此处的说明显示或下载图像: