Given an array of bytes, width, height, and a number of bits per pixel, what is the easiest way to create a WPF bitmap.
3 Answers
You can create a WriteableBitmap as you know the width, height and BPP (which will map to PixelFormat). You can then write the bytes to the WriteableBitmap with WritePixels.
Comments
There are a few parameters you should keep in mind when creating a BitmapSource from scratch in WPF. In this case it looks like you are looking for a solution to a very specific image. In your situation I normally use a helper class that encapsulate all these parameters and provide a simple approach to modify the pixels in a matrix way in case you need it. Finally, the way I use to obtain the bitmap is this:
BitmapSource.Create(Width, Height, DpiX, DpiY, PixelFormat, null, PixelData, Stride);
You can take a look at the entire class here.