I'm Unable to capture <img />
inside the screen capture area.
I want a defined section with images and content to be captured. How can we achieve this? Help!
Visit: https://stackblitz.com/edit/ngx-capture-div-angular-wnkjwz?file=src/app/app.component.html
.html
<div #screen style="background: red; color: #FFFFFF">
<img
width="100"
height="100"
alt="image"
src="https://images.unsplash.com/photo-1546961329-78bef0414d7c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80"
/>
<hello name="{{ name }}"></hello>
<p>Start editing to see some magic happen :)</p>
</div>
<button (click)="onCapture()">Capture</button>
<img src="{{ img }}" />
Component.ts
import { Component, ViewChild } from "@angular/core";
import { NgxCaptureService } from "ngx-capture";
import { tap } from "rxjs/operators";
// ----------------------------------------------------------------------------
// "THE BEER-WARE LICENSE" (Revision 42):
// @tmalicet wrote this file. As long as you retain this notice you
// can do whatever you want with this stuff. If we meet some day, and you think
// this stuff is worth it, you can buy me a beer in return. Thomas Malicet
// ----------------------------------------------------------------------------
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
public name = "Angular";
public img = "";
@ViewChild("screen", { static: true }) screen: any;
constructor(private captureService: NgxCaptureService) {}
onCapture() {
this.captureService
.getImage(this.screen.nativeElement, true)
.pipe(
tap(img => {
this.img = img;
console.log(img);
})
)
.subscribe();
}
}