Пример #1
0
        public static byte[] ToBitmap(this byte[] target, byte type)
        {
            byte[] result = null;

            int width  = 0;
            int height = 0;

            if (type == 0)
            {
                return(result);
            }

            else if (type == 1)
            {
                width  = 120;
                height = 24;
            }

            else if (type == 2)
            {
                width  = 120;
                height = 16;
            }

            else if (type == 3)
            {
                width  = 60;
                height = 16;
            }

            List <Color> source = new List <Color>();

            foreach (byte item in target)
            {
                for (int i = 7; i >= 0; i--)
                {
                    source.Add(item.GetBit(i) ? Color.Black : Color.White);
                }
            }

            Bitmap image = new Bitmap(width, height);

            int index = 0;

            for (int column = 0; column < width; column++)
            {
                for (int row = 0; row < height; row++)
                {
                    image.SetPixel(column, row, source[index]);

                    index += 1;
                }
            }

            using (MemoryStream objMS = new MemoryStream())
            {
                image.AdjustQuality(objMS, 25);

                result = objMS.ToArray();
            }

            return(result);
        }