My goal is to work with bitmaps but store them as PNG bit arrays. I have:
BitmapImage imageGrass = (BitmapImage)this.FindResource("imageGrass");
I am curious at this point if this is a bitmap or a PNG. If i user copy pixels I know for sure its uncompressed bitmap. Where I am failing is:
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(imageGrass));
byte[] imageData;
using (MemoryStream imageStream = new MemoryStream())
{
encoder.Save(imageStream);
imageData = new byte[imageStream.Length];
imageStream.Read(imageData, 0, (int)imageStream.Length);
imageStream.Flush();
imageStream.Close();
}
now this may be related to the memory stream because I can encode and save to a file.
MAIN QUESTION: How can I store a PNG byte array?