Files
SpectraElement/HardwareControl.Core/UsbCamera/CameraFrameFormat.cs
T
2026-11-13 09:51:38 +08:00

35 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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));
}
}