嘿所有我试图想出一种在图像控件中自定义网络摄像头图像大小的方法。
目前,这是绘制图像的代码:
private void video_NewFrame(object sender, Video.NewFrameEventArgs eventArgs)
{
try
{
BitmapImage bi;
ResizeBicubic filter = new ResizeBicubic(400, 300);
using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
{
bi = bitmap.ToBitmapImage();
}
bi.Freeze(); // avoid cross thread operations and prevents leaks
Dispatcher.BeginInvoke(new ThreadStart(delegate { videoPlayer.Source = bi; }));
}
catch (Exception exc)
{
MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
StopCamera();
}
}
如你所见,我正在尝试使用 ResizeBicubic filter = new ResizeBicubic(400,300); 来调整它的大小,但我似乎无法找到放置filter.Apply()的任何地方。 / p>
如果我这样做:
filter.Apply(bi);
它给了我错误:
参数1:无法从'System.Windows.Media.Imaging.BitmapImage'转换为'System.Drawing.Bitmap'
我还有代码可以找到特定网络摄像头可以执行的最大视频资源:
private void StartCamera()
{
if (CurrentDevice != null)
{
_videoSource = new VideoCaptureDevice(CurrentDevice.MonikerString);
if (_videoSource.VideoCapabilities.Length > 0)
{
string highestSolution = "0;0";
//Search for the highest resolution
for (int i = 0; i < _videoSource.VideoCapabilities.Length; i++)
{
if (_videoSource.VideoCapabilities[i].FrameSize.Width > Convert.ToInt32(highestSolution.Split(';')[0]))
highestSolution = _videoSource.VideoCapabilities[i].FrameSize.Width.ToString() + ";" + i.ToString();
}
_videoSource.VideoResolution = _videoSource.VideoCapabilities[Convert.ToInt32(highestSolution.Split(';')[1])];
}
_videoSource.NewFrame += video_NewFrame;
_videoSource.Start();
}
}
该代码可以将图像设置为屏幕上最大的尺寸,但就像我说的那样,我希望将该尺寸自定义为实际图像控件的大小。
任何帮助都会很棒!