I have a 1 dimensional array of bytes, with separate values for A, R, G, and B, and I know the height and width of the expected image. How can I encode this data and save it as a PNG?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
If the values in your array are ordered this way: B G R A B G R A B G R A ... you could use the following code, which should be faster:
This image should look like this:
You can use a Bitmap and Bitmap.SetPixel().
Then save the Bitmap as png using
ImageFormat.Png
. Also, you might have to make sure that the Bitmap format maintains transparency .(See the other answer here for a faster way than SetPixel.)
EDIT
Perhaps WPF can use the array directly. (I don't have much experience with it.)
Her's a faster solution using
Unsafe pointers
andLockBits
Just fill the
p[]
values like they stored in your array.Goodluck.