如何使用NGX-WEBCAM捕获照片录制视频
我目前正在使用可以在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ngx-webcam尚未支持盒子录制。 https://github.com/basst314/ngx-webcam/ngx-webcam/sissues/38
&nbsp;
它内置的功能
&nbsp;
&nbsp;
我建议研究不同的软件包或方法。
&nbsp;
&nbsp;
您可能必须最终获得较低的水平并构建自己的解决方案。
&nbsp;
ngx-webcam doesnt support out of the box recording, yet. https://github.com/basst314/ngx-webcam/issues/38
Its built in feature
I suggest looking into different packages or approaches.
You may have to end up getting a little lower level and building your own solution.