简体   繁体   English

渲染时,离子dom-to-image插件崩溃

[英]Ionic dom-to-image plugin crash when rendering

I can't show any code, because the problem isn't give me an error, a message or anything. 我无法显示任何代码,因为问题不是给我一个错误,一条消息或任何东西。

I have this situation: My app had to do 2 renders with domToImage . 我有这种情况:我的应用程序必须使用domToImage进行2次渲染。

First, I get an image from Camera/Gallery (base64) Then adding to img.src it renders for a simple background. 首先,我从Camera / Gallery(base64)获取一个图像然后添加到img.src它呈现一个简单的背景。 I put this bg under a set of Dom elements and then render it all together This process was happening fine, no problems, no errors, no bugs. 我将这个bg放在一组Dom元素下,然后将它们全部渲染在一起这个过程发生得很好,没有问题,没有错误,没有错误。

Until out of a sudden it start crashing the app. 直到突然它开始崩溃的应用程序。 I didn't make any update, any change on my code at all. 我没有对我的代码进行任何更新,任何更改。 It was working, and then it wasn't. 它工作,但事实并非如此。

I remade the process and downsized to just on render. 我重新制作了这个过程并缩小到渲染。 Still crashes. 仍然崩溃。

There's no pattern on action. 行动没有模式。 It crashes under bg render or the set render, or sometimes don't. 它会在bg渲染或set渲染下崩溃,有时则不会崩溃。 But it don't miss 2 in a row. 但它不会错过2连胜。 If doesn't fail the first routine, the 2nd will. 如果第一个例程没有失败,第二个例程就会失败。 Anywhere. 无处不在。

I'm lost... A added Xwalk, removed, created from the ground another equal project, still crashes. 我迷路了...一个额外的Xwalk,被移除,从地面创建另一个相同的项目,仍然崩溃。 Changed the plugin importation, even reset the smartphone for a certain clean installation... Is not my phone's problem cause a bunch of clients around the world are reporting this bug. 更改了插件导入,甚至重置智能手机以进行某种干净的安装...不是我的手机问题导致世界各地的一些客户报告此错误。

Any direction? 任何方向?

Using Dom-to-Image 2.6.0 使用Dom-to-Image 2.6.0

Ionic 3 - Android Platform Ionic 3 - Android平台

Som code: 索姆代码:

home.ts 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 的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"
    ]
  }
}

I suggest that you can try to achieve that goal with another Js package. 我建议你可以尝试用另一个Js包来实现这个目标。 Let's try html2canvas : 我们来试试html2canvas

Installation 安装

npm install --save html2canvas

Import 进口

import html2canvas from 'html2canvas';

Usage 用法

var element = document.getElementById('div-to-render');
html2canvas(element, { allowTaint : true }).then((canvas) =>
{
  canvas.getContext('2d');
  var image = canvas.toDataURL('image/jpeg', 1.0);
});

Now you can display or download the image as explained here : https://stackoverflow.com/a/17407392 现在,您可以按照此处的说明显示或下载映像: https//stackoverflow.com/a/17407392

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM