MVVM WPF网络摄像头不起作用..? [英] MVVM WPF Webcam Not Working..?
问题描述
我正在一个项目上,需要通过mvvm模式流式传输视频.我在代码中获取了视频.但是我无法以mvvm模式中获取视频.
在xaml中用于按钮和图像控制:-
i am working on a project and need to stream video through mvvm pattern.i got video in code behind.but i can''t get video in mvvm pattern.
in xaml for button and image control :-
<Button Command="{Binding StartCommand}" Content="Start" Grid.Row="4" Height="38" Margin="9" Name="btnwebcamstart" Width="{StaticResource btnWidth}"/>
<Image Source="{Binding Source=Imagevideo}" Margin="9" Name="patientvideo" Stretch="Fill" Width="120" Grid.RowSpan="2" Height="104" Grid.Row="1" />
我只是制作一个图片属性:
i just make one image property:
public Image Imagevideo
{
get
{
return imagevideo;
}
set
{
imagevideo = value;
OnPropertyChaged("Imagevideo");
}
}
WebCam是一个.cs文件.
在构造函数中,我写道:-
WebCam is a .cs file .
in constructor i write:-
WebCam webcam=new webcam();
webcam.InitializeWebCam(ref Imagevideo);
this.StartCommand = new DelegateCommand<object>(this.patientvideostart);
}
public void InitializeWebCam(ref System.Windows.Controls.Image ImageControl)
{
webcam = new WebCamCapture();
webcam.FrameNumber = ((ulong)(0ul));
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
_FrameImage = ImageControl;
}
void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
_FrameImage.Source = LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
}
public static BitmapSource LoadBitmap(System.Drawing.Bitmap source)
{
ip = source.GetHbitmap();
bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
return bs;
}
我只是从.cs文件调用一个启动方法
i just call one start method from .cs file
public void patientvideostart(object parameter)
{
webcam.Start();
}
//webcam.InitializeWebCam(ref Imagevideo);
在"ref imagevideo"后面的代码中是一个图像控件.我更改为属性"ref Imagevideo".因此在这里,我得到了错误.
属性,索引器或动态成员访问不能作为out或ref参数传递"
我如何才能在mvvm.advance中获得视频流.谢谢.
in code behind "ref imagevideo" is a image control .i changed to a property"ref Imagevideo".so in here i got the error.
"A property,indexer or dynamic member access may not be passed as an out or ref parameter"
what i can do for getting the video streaming in mvvm.advance thanks..
<pre lang="c#">
推荐答案
错误非常明显-您无法将属性传递给方法的ref参数.
您需要临时设置:
Hi,
The error is pretty clear - you can''t pass a property to a ref parameter of a method.
You need to make a temporary:
var circle = painting.Circles[mutationIndex];
MutatePosition(ref circle, painting.Width, painting.Height);
painting.Circles[mutationIndex] = circle;
话虽这么说,可变结构通常不是一个好主意.您可能要考虑使它成为类而不是结构.
请看以下CP文章:将YouTube API 1.9.0.0与MVVM-Light-Toolkit一起使用 [
That being said, mutable structs are often a bad idea. You might want to consider making this a class instead of a struct.
Have a look at the following CP article: Using YouTube API 1.9.0.0 with MVVM-Light-Toolkit[^] - it might shed some light on the issue.
Kind regards,
这篇关于MVVM WPF网络摄像头不起作用..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!