Question: 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?

Answer: 
You can use a Bitmap and [Bitmap.SetPixel()](https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setpixel%28v=vs.110%29.aspx).

Then [save the Bitmap as png](https://msdn.microsoft.com/en-us/library/9t4syfhh%28v=vs.110%29.aspx) using `ImageFormat.Png` . Also, you might have to make sure that [the Bitmap format maintains transparency](https://stackoverflow.com/a/7666180/939213) .

(See the other answer here for a faster way than SetPixel.)

EDIT

Perhaps [WPF](https://msdn.microsoft.com/en-us/library/aa346816%28v=vs.110%29.aspx) can use the array directly. (I don't have much experience with it.)
Here's a faster solution using `Unsafe pointers` and `LockBits`

```
    public unsafe Bitmap Retreive(byte[] values)
    {
        Bitmap bmp = new Bitmap(Width, Height); //enter your width and height here.
        BitmapData bmData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);
        IntPtr scan0 = bmData.Scan0;
        int stride = bmData.Stride;
        int nWidth = bmp.Width;
        int nHeight = bmp.Height;

        for (int y = 0; y < nHeight; y++)
        {
            //define the pointers inside the first loop for parallelizing
            byte* p = (byte*)scan0.ToPointer();
            p += y * stride;

            for (int x = 0; x < nWidth; x++)
            {
                //fill as  the values stored in you byte array;
                p[0] = values[0];// R component.
                p[1] = values[1];// G component.
                p[2] = values[2];// B component.
                p[3] = values[3];// Alpha component.
                p += 4;
            }
        }

        bmp.UnlockBits(bmData);
        return bmp;
    }

```

Just fill the `p[]` values like they stored in your array. 

Goodluck.