【问题标题】:crop image using html2canvas in angular 2 typescript在angular 2 typescript中使用html2canvas裁剪图像
【发布时间】:2023-04-06 23:20:02
【问题描述】:

我正在使用 html2canvas 以 Angular 2 捕获网页屏幕

import { Component, OnInit, NgZone } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import * as html2canvas from "html2canvas";


@Component({
    selector: 'test',
    templateUrl: 'app/components/view/view.component.html',
    styleUrls: ['app/components/view/view.component.css']
})
export class ViewComponent {
    
   

    constructor(
        private sanitizer: DomSanitizer,
        private window: WindowRef) {
    }

    ngOnInit() {
      this.pdfDownload();
    }

    pdfDownload() {
        html2canvas(document.body).then(function (canvas) {
            var imgData = canvas.toDataURL("image/png");
        });
    }


}

我想裁剪捕获的图像的边框,因为屏幕截图也在捕获导航栏并且不希望发生这种情况。你能告诉我如何实现上述功能吗?

【问题讨论】:

    标签: html angular typescript canvas html2canvas


    【解决方案1】:
    html2canvas(document.body)
    

    改变 document.body
    $("[CLASS OR ID]")
    

    对于需要快照的元素或部分元素!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 2017-05-22
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多