Пример #1
0
        private List <MatrixWord> GetDot(String txt, int Width, int Height, String FontName, int FontSize, out Bitmap pic)
        {
            List <MatrixWord> words = new List <MatrixWord>();

            char[] a       = txt.ToCharArray();
            string Str     = "";
            Bitmap big     = new Bitmap(128, 128);
            int    line    = 0;
            int    colChar = 100;

            for (int i = 0; i < a.Length; i++)
            {
                var word = new MatrixWord(a[i], Width, Height, FontName, FontSize);
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        big.SetPixel(x + (i % colChar) * Width, y + (int)(i / colChar) * Height, word.square.GetPixel(x, y));
                    }
                }
                if ((i + 1) % colChar * Width >= big.Width)
                {
                    colChar = colChar > (i + 1) ? (i + 1) : colChar;
                }
                words.Add(word);
            }
            pic = big;
            return(words);
        }
Пример #2
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="c"></param>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <param name="FontName"></param>
        /// <param name="FontSize"></param>
        /// <returns></returns>
        public static MatrixWord Convert(char c, int Width, int Height, String FontName, int FontSize)
        {
            Bitmap     b     = new Bitmap(Width, Height);
            RectangleF rectf = new RectangleF(0, 0, Width, Height);
            Graphics   g     = Graphics.FromImage(b);

            //g.SmoothingMode = SmoothingMode.AntiAlias;
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawString(c.ToString(), new Font(FontName, FontSize), Brushes.Black, rectf);
            g.Flush();
            //pictureBox1.Image = new Bitmap(b, 128, 128);
            string       DotMartix = "";
            List <Int32> hexList   = new List <int>();

            for (int y = 0; y < b.Height; y++)
            {
                string Line = "";
                int    hex  = 0;
                for (int x = 0; x < b.Width; x++)
                {
                    if (b.GetPixel(x, y).Name != "0")
                    {
                        Line += "● ";
                        hex  += 1 << (7 - x % 8);
                    }
                    else
                    {
                        Line += "○ ";
                    }
                    //8个bit分割
                    if ((x + 1) % 8 == 0)
                    {
                        hexList.Add(hex);
                        hex = 0;
                    }
                }

                DotMartix += Line + "\r\n";
            }
            MatrixWord word = new MatrixWord
            {
                word   = c,
                square = b,
                maping = DotMartix,
                hexArr = hexList
            };

            return(word);
        }
Пример #3
0
 private List<MatrixWord> GetDot(String txt, int Width, int Height, String FontName, int FontSize, out Bitmap pic)
 {
     List<MatrixWord> words = new List<MatrixWord>();
     char[] a = txt.ToCharArray();
     string Str = "";
     Bitmap big = new Bitmap(128, 128);
     int line = 0;
     int colChar = 100;
     for (int i = 0; i < a.Length; i++)
     {
         var word = new MatrixWord(a[i], Width, Height, FontName, FontSize);
         for (int y = 0; y < Height; y++)
             for (int x = 0; x < Width; x++)
                 big.SetPixel(x + (i % colChar) * Width, y + (int)(i / colChar) * Height, word.square.GetPixel(x, y));
         if ((i + 1) % colChar * Width >= big.Width)
             colChar = colChar > (i + 1) ? (i + 1) : colChar;
         words.Add(word);
     }
     pic = big;
     return words;
 }
Пример #4
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="c"></param>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <param name="FontName"></param>
        /// <param name="FontSize"></param>
        /// <returns></returns>
        public static MatrixWord Convert(char c, int Width, int Height, String FontName, int FontSize)
        {
            Bitmap b = new Bitmap(Width, Height);
            RectangleF rectf = new RectangleF(0, 0, Width, Height);
            Graphics g = Graphics.FromImage(b);

            //g.SmoothingMode = SmoothingMode.AntiAlias;
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawString(c.ToString(), new Font(FontName, FontSize), Brushes.Black, rectf);
            g.Flush();
            //pictureBox1.Image = new Bitmap(b, 128, 128);
            string DotMartix = "";
            List<Int32> hexList = new List<int>();
            for (int y = 0; y < b.Height; y++)
            {
                string Line = "";
                int hex = 0;
                for (int x = 0; x < b.Width; x++)
                {
                    if (b.GetPixel(x, y).Name != "0")
                    {
                        Line += "● ";
                        hex += 1 << (7 - x % 8);
                    }
                    else
                    {
                        Line += "○ ";
                    }
                    //8个bit分割
                    if ((x + 1) % 8 == 0)
                    {
                        hexList.Add(hex);
                        hex = 0;
                    }
                }

                DotMartix += Line + "\r\n";
            }
            MatrixWord word = new MatrixWord
                {
                    word = c,
                    square = b,
                    maping = DotMartix,
                    hexArr = hexList
                };
                return word;
        }