tags:

views:

38

answers:

1

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?

A: 

This article should make it trivial for you. http://www.vcskicks.com/image-to-byte.php

Good luck.

keyle
The problem is, the article uses GDI+ and I am using WPF. I am used to working with GDI+ but I am trying to learn WPF. WPF uses directX underneath and a direction Windows is going. I do thank you for your article though.
Jonathan Kaufman