35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using FlashCap;
|
||
|
||
namespace HardwareControl.Core.UsbCamera
|
||
{
|
||
/// <summary>
|
||
/// 当前采集格式。前端用它选择正确的 data URL MIME,
|
||
/// MJPG/PNG 帧可直接显示,YUV 等格式由 FlashCap 转码为 BMP。
|
||
/// </summary>
|
||
public sealed record CameraFrameFormat(
|
||
int Width,
|
||
int Height,
|
||
string PixelFormat,
|
||
double FramesPerSecond,
|
||
string MimeType)
|
||
{
|
||
public bool IsCompressed => MimeType is "image/jpeg" or "image/png";
|
||
|
||
public static string ResolveMimeType(PixelFormats pixelFormat) =>
|
||
pixelFormat switch
|
||
{
|
||
PixelFormats.JPEG => "image/jpeg",
|
||
PixelFormats.PNG => "image/png",
|
||
_ => "image/bmp",
|
||
};
|
||
|
||
public static CameraFrameFormat From(VideoCharacteristics characteristics) =>
|
||
new(
|
||
characteristics.Width,
|
||
characteristics.Height,
|
||
characteristics.PixelFormat.ToString(),
|
||
(double)characteristics.FramesPerSecond,
|
||
ResolveMimeType(characteristics.PixelFormat));
|
||
}
|
||
}
|