2

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 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

If your array is already in a format listed by PixelFormats, you may directly use BitmapSource.Create().

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.