Пример #1
0
        static void Main(string[] args)
        {
            var charSize = 16f;
            var charBmps = CharBitMapGenerator.GenerateCharBitMapImages(charSize);

            var grayScaleBmps = charBmps.Select(x => (BmpToGrayScalePixels(x.bmp), x.chr)).ToList();

            var img = Image.FromFile(@"E:\repos\ImageToAscii\mount1.jpg");

            Bmp bmp;

            using (var ms = new MemoryStream())
            {
                img.Save(ms, ImageFormat.Bmp);
                bmp = BmpParser.Parse(ms.ToArray());
            }

            var grayscale = Invert(BmpToGrayScalePixels(bmp));

            var m = 0;

            foreach (var p in grayscale)
            {
                m = Math.Max(p, m);
            }
            var resString = ImageToText.GenerateImageString(grayscale, grayScaleBmps);


            File.WriteAllText(@"../../../../out.txt", resString);
        }
Пример #2
0
        public void BmpParseSave(string fileName)
        {
            var bytes    = File.ReadAllBytes(fileName);
            var bmp      = BmpParser.Parse(bytes);
            var outbytes = bmp.GetFileBytes();

            Assert.IsTrue(bytes.Length == outbytes.Length);

            for (var i = 0; i < bytes.Length; i++)
            {
                Assert.AreEqual(bytes[i], outbytes[i]);
            }
        }
Пример #3
0
        public void BmpFromPixels(string fileName)
        {
            var bytes        = File.ReadAllBytes(fileName);
            var bmpFromBytes = BmpParser.Parse(bytes);
            var bmp          = BmpParser.FromPixels(bmpFromBytes.Pixels, bmpFromBytes.InfoHeader.BitPerPixel);

            bmp.InfoHeader.BitPerPixel = bmpFromBytes.InfoHeader.BitPerPixel;
            var outbytes = bmp.GetFileBytes();

            Assert.IsTrue(bytes.Length == outbytes.Length);

            for (var i = 0; i < bytes.Length; i++)
            {
                Assert.AreEqual(bytes[i], outbytes[i]);
            }
        }
Пример #4
0
        static Bmp CharBmp(char c, float size)
        {
            var font = new Font("Consolas", size);

            var bitmap = new Bitmap(100, 100);


            var s = c.ToString();
            var g = Graphics.FromImage(bitmap);

            g.DrawString(s, font, new SolidBrush(Color.White), 0, 0);
            g.Save();


            Bmp bmp;

            using (var ms = new MemoryStream())
            {
                bitmap.Save(ms, ImageFormat.Bmp);
                bmp = BmpParser.Parse(ms.ToArray());
            }

            return(Binary(bmp));
        }