Example #1
0
        internal static byte[] ImgtoBclim(Image img, char fc)
        {
            Bitmap       mBitmap     = new Bitmap(img);
            MemoryStream ms          = new MemoryStream();
            int          bclimformat = 7;    // Init to default (for X)

            if (fc == 'X')
            {
                Bclim.Write16BitColorPalette(mBitmap, ref ms);
            }
            else
            {
                bclimformat = Convert.ToInt16(fc.ToString(), 16);
                try
                {
                    Bclim.WriteGeneric(bclimformat, mBitmap, ref ms);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }
            }

            long datalength = ms.Length;

            // Write the CLIM + imag data.
            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                bw.Write((uint)0x4D494C43);                  // CLIM
                bw.Write((ushort)0xFEFF);                    // BOM
                bw.Write((uint)0x14);
                bw.Write((ushort)0x0202);                    // 2 2
                bw.Write((uint)(datalength + 0x28));
                bw.Write((uint)1);
                bw.Write((uint)0x67616D69);
                bw.Write((uint)0x10);
                bw.Write((ushort)mBitmap.Width);
                bw.Write((ushort)mBitmap.Height);
                bw.Write((uint)bclimformat);
                bw.Write((uint)datalength);
            }
            return(ms.ToArray());
        }