Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is a fast way to generate and draw video in WPF?
    text
    copied!<p>I am writing a video player to play back frames captured by our ASIC. They are in a custom format, and I have been provided with a function that decodes the ASIC states. The video can be any size from 640x480 to 2560x1200 (!!!). The output of each state cycle is a 16x16 blocks of pixels, which I have to get into a video on the screen.</p> <p>Every time the screen needs to be updated, I have the following information:</p> <ul> <li>Block width</li> <li>Block height</li> <li>X coordinate of block start</li> <li>Y coordinate of block start</li> <li>A 1-D array of RGB32 pixel color info</li> </ul> <p>Major limitations:</p> <ul> <li>.NET 3.5</li> <li>No unsafe code</li> </ul> <p>I spent this morning trying out a WriteableBitmap, and using it as a source for an Image, something like this:</p> <pre><code> private WriteableBitmap ImageSource; public MainWindow() { InitializeComponent(); ImageSource = new WriteableBitmap(FrameWidth, FrameHeight, 96, 96, PixelFormats.Bgr32, null); ImagePanel.Source = ImageSource; } private void DrawBox(byte Red, byte Green, byte Blue, int X, int Y) { int BoxWidth = 16; int BoxHeight = 16; int BytesPerPixel = ImageSource.Format.BitsPerPixel / 8; byte[] Pixels = new byte[BoxWidth * BoxHeight * BytesPerPixel]; for (int i = 0; i &lt; Pixels.Length; i += 4) { Pixels[i + 0] = Blue; Pixels[i + 1] = Green; Pixels[i + 2] = Red; Pixels[i + 3] = 0; } int Stride = BoxWidth * BytesPerPixel; Int32Rect DrawBox = new Int32Rect(X, Y, BoxWidth, BoxHeight); ImageSource.Lock(); ImageSource.WritePixels(DrawBox, Pixels, Stride, 0); ImageSource.Unlock(); } </code></pre> <p>It works, my video plays on the screen, but it is sloooooooow. Nowhere near real-time play speed. Is there a better way, besides procedurally generating a series of bitmaps, to do this that I'm not seeing? I've read something about D3Dimage, but it seems that's more for exporting a 3D scene to a bitmap. Suggestions here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload