Reputation: 113
Given an array of bytes, width, height, and a number of bits per pixel, what is the easiest way to create a WPF bitmap.
Upvotes: 2
Views: 169
Reputation: 332
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.
Upvotes: 0
Reputation: 2275
If your array is already in a format listed by PixelFormats, you may directly use BitmapSource.Create().
Upvotes: 1
Reputation: 38434
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.
Upvotes: 4