I have a C#/WPF program which use EMGU to manipule a 4K video (image per image). I am doing some operations on the image like rotation, crop … these operations are fast.
My problem is that it take a long time to display the image (40ms). If I add my operations to this time I have less than 20FPS. Displaying the image is 70% of the time.
I am using this code :
<Image x:Name="VideoWidget" Stretch="Uniform"/>
if (_cameraWritableBitmap == null || _cameraWritableBitmap.PixelWidth != width || _cameraWritableBitmap.PixelHeight != height)
{
_cameraWritableBitmap = new WriteableBitmap(
width,
height,
dpiX,
dpiY,
pixelFormat,
null);
_mainWindow.VideoWidget.Source = _cameraWritableBitmap;
OnPropertyChanged("ZoomImage");
OnPropertyChanged("ZoomScreen");
OnPropertyChanged("IsZoomImageAlert");
OnPropertyChanged("IsZoomScreenAlert");
}
timePrev = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
_cameraWritableBitmap.Lock();
_cameraWritableBitmap.WritePixels(new Int32Rect(0, 0, width, height), imgColor.Bytes, width * 4, 0);
//Marshal.Copy(imgColor.Bytes, 0, _cameraWritableBitmap.BackBuffer, imgColor.Bytes.Length);
//_cameraWritableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
_cameraWritableBitmap.Unlock();
Console.WriteLine("# ECRITURE " + (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - timePrev));
Do you know a fastest way to display my image ?
Thank you,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…