如何使用NGX-WEBCAM捕获照片录制视频

发布于 2025-02-04 01:18:33 字数 1404 浏览 2 评论 0原文

我目前正在使用可以在Angular应用中录制视频的相机。当前,使用以下代码,我可以访问相机并拍摄快照。

有人可以建议我在代码中要修改的内容以便有能力拍摄视频吗?

app.module.ts文件:

import {WebcamModule} from 'ngx-webcam';
...
imports: [
    ...
    WebcamModule
]

app.component.ts文件:

import {WebcamImage} from 'ngx-webcam';
import {Subject, Observable} from 'rxjs';
...
export class AppComponent {
...
   // latest snapshot
   public webcamImage: WebcamImage = null;
   // webcam snapshot trigger
   private trigger: Subject<void> = new Subject<void>();
   triggerSnapshot(): void {
    this.trigger.next();
   }
   handleImage(webcamImage: WebcamImage): void {
    console.info('received webcam image', webcamImage);
    this.webcamImage = webcamImage;
   }
  
   public get triggerObservable(): Observable<void> {
    return this.trigger.asObservable();
   }
}

app.component.html文件:

<webcam [height]="500" [width]="500" [trigger]="triggerObservable" (imageCapture)="handleImage($event)"></webcam>
<!-- Button Takes Photo -->
<button class="actionBtn" (click)="triggerSnapshot();">Take A Snapshot</button>
<!-- Snapshot Div where image will be shown -->
<div class="snapshot" *ngIf="webcamImage">
  <h2>Take your image or get another</h2>
  <img [src]="webcamImage.imageAsDataUrl"/>
</div>

I am currently working on a camera that would record videos in my angular app. Currently, with the below code, I can access my camera and take snapshots.

Can someone please advise what I should amend in my code in order to have the ability to take a video?

App.module.ts file:

import {WebcamModule} from 'ngx-webcam';
...
imports: [
    ...
    WebcamModule
]

app.component.ts file:

import {WebcamImage} from 'ngx-webcam';
import {Subject, Observable} from 'rxjs';
...
export class AppComponent {
...
   // latest snapshot
   public webcamImage: WebcamImage = null;
   // webcam snapshot trigger
   private trigger: Subject<void> = new Subject<void>();
   triggerSnapshot(): void {
    this.trigger.next();
   }
   handleImage(webcamImage: WebcamImage): void {
    console.info('received webcam image', webcamImage);
    this.webcamImage = webcamImage;
   }
  
   public get triggerObservable(): Observable<void> {
    return this.trigger.asObservable();
   }
}

app.component.html file:

<webcam [height]="500" [width]="500" [trigger]="triggerObservable" (imageCapture)="handleImage($event)"></webcam>
<!-- Button Takes Photo -->
<button class="actionBtn" (click)="triggerSnapshot();">Take A Snapshot</button>
<!-- Snapshot Div where image will be shown -->
<div class="snapshot" *ngIf="webcamImage">
  <h2>Take your image or get another</h2>
  <img [src]="webcamImage.imageAsDataUrl"/>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

跨年 2025-02-11 01:18:34

ngx-webcam尚未支持盒子录制。 https://github.com/basst314/ngx-webcam/ngx-webcam/sissues/38
&nbsp;
它内置的功能
&nbsp;

ngx-webcam doesnt support out of the box recording, yet. https://github.com/basst314/ngx-webcam/issues/38

Its built in feature  

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文