Set Quality of Png with html2canvas

后端 未结 3 1099
生来不讨喜
生来不讨喜 2020-12-18 15:14
        html2canvas($(\"#Element\"), {
  onrendered: function(canvasq) {
    var w=window.open();
    w.document.write(\"

\"+Re

3条回答
  •  隐瞒了意图╮
    2020-12-18 15:17

    the approach with css scale is correct.

    first we need to scale up element, then in "html2canvas" callback scale it down.

    var ELEMENT = jQuery("#ELEMENT");
    
    //get element width and height
    var w = ELEMENT.width();
    var h = ELEMENT.height();
    
    //scale up your element
    ELEMENT.css({
    'transform': 'scale(3)',
    '-ms-transform': 'scale(3)',
    '-webkit-transform': 'scale(3)' });
    
    //run html2canvas
    html2canvas(ELEMENT, {
    onrendered: function(canvas) {
    
    //scale back your element
    ELEMENT.css({
    'transform': '',
    '-ms-transform': '',
    '-webkit-transform': '' });
    
    //your actions to canvas
    var win = window.open();
    win.document.write('

    ttl

    '); win.document.write(''); win.print(); }, //set proper canvas width and height width: w*3, height: h*3 });

提交回复
热议问题