Exemple #1
0
        private int[] FindNearestShader(int[] pure)
        {
            int nuPure  = ShadeToInt(pure);
            int nearest = AvailableShadeInts.OrderBy(x => (Math.Abs(x - nuPure))).First();

            return(ShadeMap[nearest]);
        }
Exemple #2
0
        private Dictionary <int[], Bitmap> CalculateFontShades()
        {
            SetWindowStatus("Calculating font shaders...");

            Dictionary <int[], Bitmap> retDict = new Dictionary <int[], Bitmap>();
            int fontIndex = cmboFonts.SelectedIndex;

            this.ASCIIChars         = new Dictionary <int[], char>();
            this.AvailableShades    = new List <int[]>();
            this.AvailableShadeInts = new List <int>();
            this.ShadeMap           = new Dictionary <int, int[]>();
            int mX = 0;
            int mY = 0;

            System.Drawing.Image bmp = new Bitmap(100, 100);
            for (int i = 0; i < AvailableASCIIString.Length; i++)
            {
                // Find pixel size, and create bitmap of character
                Graphics g = Graphics.FromImage(bmp);

                Font   myFont = new Font(FormsFontIndexer[fontIndex], SelectedFontSize, GraphicsUnit.Pixel);
                SizeF  size   = g.MeasureString(AvailableASCIIString[i].ToString(), myFont);
                PointF rect   = new PointF(size.Width, size.Height);
                mX = (int)rect.X;
                mY = (int)rect.Y;
                //System.Windows.MessageBox.Show(""+(myFont.SizeInPoints / 72 * g.DpiX));

                //System.Windows.MessageBox.Show("X:"+ (int)rect.X+"\nY:"+(int)rect.Y+"\nfX"+rect.X+"\nfY:"+rect.Y);
                Bitmap outBmp = new Bitmap((int)rect.X, (int)rect.Y, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                //todo set pixelformat
                Graphics o = Graphics.FromImage(outBmp);
                o.Clear(System.Drawing.Color.White);
                o.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                o.InterpolationMode = InterpolationMode.HighQualityBicubic;
                o.PixelOffsetMode   = PixelOffsetMode.None;
                //System.Windows.MessageBox.Show("" + AvailableASCIIString[i]);
                o.DrawString(AvailableASCIIString[i].ToString(), myFont, System.Drawing.Brushes.Black, 0, 0);
                outBmp.Save("./outbmp.bmp");
                // Determine shade
                int[] shade = PullAverageRGBFromBmp(outBmp);


                // Check if any letter has the same shade (if so, skip)
                string StrShade = "" + shade[0] + "" + shade[1] + "" + shade[2];
                int    intShade = Int32.Parse(StrShade);
                //if (!ASCIIChars.ContainsKey(shade) && !ShadeMap.ContainsKey()
                if (!ShadeMap.ContainsKey(intShade))
                {
                    ASCIIChars.Add(shade, AvailableASCIIString[i]);
                    retDict.Add(shade, outBmp);
                    AvailableShades.Add(shade);
                    AvailableShadeInts.Add(intShade);
                    ShadeMap.Add(intShade, shade);
                }


                g.Dispose();
                o.Dispose();
                outBmp.Dispose();
            }

            bmp.Dispose();
            this.BitmapXY = new int[] { mX, mY };
            return(retDict);
        }