color palette in oxyimage

Aug 19, 2013 at 2:34 PM
I am not sure how to apply color palette in an oxyimage.

I made a byte array by scaling my array in [0,255], and then I want to apply gray(255) scaling on the data. but image decoder throws error, I am pasting my code below. Please help.
            var pallet = new OxyColor[255];
            OxyPalettes.Gray(255).Colors.CopyTo(pallet, 0);
            im = OxyImage.FromIndexed8(wid, ht, bPlot,  pallet, 96);
here, wid is width( say 100), ht is height (say 100), bPlot is byte[] (size 100x100). But then I get error in image decoder which says:
The image decoder cannot decode the image. The image might be corrupted.
Thanks a lot.
Coordinator
Aug 22, 2013 at 8:49 PM
Edited Aug 22, 2013 at 8:52 PM
Maybe the palette should have 256 entries?

The following should work:
        [Test]
        public void Discussion453825()
        {
            var data = new byte[100 * 100];
            int k = 0;
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    data[i + (j * 100)] = (byte)(k++ % 256);
                }
            }

            var palette = OxyPalettes.Gray(256).Colors.ToArray();
            var im = OxyImage.FromIndexed8(100, 100, data, palette);
            File.WriteAllBytes("Discussion453825.bmp", im.GetData());
        }
I have added this as a unit test.
Aug 27, 2013 at 4:39 PM
that worked, but I change 100 to 199, it doesnt!!
            var data = new byte[199 * 199];
            int k = 0;
            for (int i = 0; i < 199; i++)
            {
                for (int j = 0; j < 199; j++)
                {
                    data[i + (j * 199)] = (byte)(k++ % 256);
                }
            }

            var palette1 = OxyPalettes.Gray(256).Colors.ToArray();
            var im1 = OxyImage.FromIndexed8(199, 199, data, palette1);
Coordinator
Aug 27, 2013 at 10:09 PM
Thank you - this was a bug. I have corrected it, I think (DWORD aligning rows in the BITMAP pixel data section)