/// <summary>
        /// Create a new image for the picturebox
        /// </summary>
        private void UpdateImage()
        {
            if (!this.updateImage || this.tbxSampleText.Lines.Length == 0)
            {
                return;
            }

            using (Bitmap bmpFullSize = TextToImage.Convert(this.tbxSampleText.Text, this.tbxSampleText.Font, this.TextColor, this.BackgroundColor))
            {
                if (bmpFullSize == null)
                {
                    return;
                }

                float magnification = this.Value / 100f;

                Size newSize = new Size(
                    (int)(((float)bmpFullSize.Width * magnification) + 0.5f),
                    (int)(((float)bmpFullSize.Height * magnification) + 0.5f));

                this.pbxOutputImage.Image = new Bitmap(newSize.Width, newSize.Height);

                using (ImageAttributes ia = new ImageAttributes())
                {
                    ia.SetColorMatrix(JMSoftware.Matrices.Grayscale());

                    using (Graphics g = Graphics.FromImage(this.pbxOutputImage.Image))
                    {
                        // select highest quality resize mode
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                        g.DrawImage(
                            bmpFullSize,
                            new Rectangle(0, 0, newSize.Width, newSize.Height),
                            0,
                            0,
                            bmpFullSize.Width,
                            bmpFullSize.Height,
                            GraphicsUnit.Pixel,
                            ia);
                    }
                }
            }

            this.updateImage = false;

            this.pbxOutputImage.Refresh();
        }
Beispiel #2
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     // Put user code to initialize the page here
       if(!IsPostBack)
       {
     TextToImage objTextToImage = new TextToImage();
     cboFontStyle.DataSource=objTextToImage.LoadFontStyles();
     cboFontStyle.DataBind();
     cboFontSize.DataSource=objTextToImage.LoadFontSizes();
     cboFontSize.DataBind();
     cboFontFamily.DataSource=objTextToImage.LoadFontFamily();
     cboFontFamily.DataBind();
     cboBackgroundColor.DataSource=cboForegroundColor.DataSource=objTextToImage.LoadColors();
     cboBackgroundColor.DataBind();
     cboForegroundColor.DataBind();
       }
 }
 private void Page_Load(object sender, System.EventArgs e)
 {
     // Put user code to initialize the page here
     if (!IsPostBack)
     {
         TextToImage objTextToImage = new TextToImage();
         cboFontStyle.DataSource = objTextToImage.LoadFontStyles();
         cboFontStyle.DataBind();
         cboFontSize.DataSource = objTextToImage.LoadFontSizes();
         cboFontSize.DataBind();
         cboFontFamily.DataSource = objTextToImage.LoadFontFamily();
         cboFontFamily.DataBind();
         cboBackgroundColor.DataSource = cboForegroundColor.DataSource = objTextToImage.LoadColors();
         cboBackgroundColor.DataBind();
         cboForegroundColor.DataBind();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Update Value for the passed font
        /// </summary>
        /// <param name="font">Font to be used</param>
        public void CalculateValue(Font font)
        {
            using (Bitmap bitmap = TextToImage.Convert(this.Character.ToString(), font))
            {
                if (bitmap == null)
                {
                    this.Value = -1;

                    return;
                }

                this.Width = bitmap.Width;

                int total = 0;

                unsafe
                {
                    BitmapData data = bitmap.LockBits(
                        new Rectangle(new Point(0, 0), bitmap.Size),
                        ImageLockMode.ReadOnly,
                        PixelFormat.Format24bppRgb);

                    byte *pointer = (byte *)data.Scan0;

                    int padding = data.Stride - (bitmap.Width * 3);

                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            total += (int)(((float)(pointer[2] + pointer[1] + pointer[0]) / 3f) + 0.5);

                            pointer += 3;
                        }

                        pointer += padding;
                    }

                    bitmap.UnlockBits(data);
                }

                this.Value = (int)(((float)total / (float)(this.Width * bitmap.Height)) + 0.5);
            }
        }
Beispiel #5
0
        public async Task <byte[]> GetEmailImageAsync(int?userId)
        {
            if (userId == null)
            {
                return(TextToImage.EMailToImage("?"));
            }

            var user = await FindByIdAsync(userId.Value.ToString()).ConfigureAwait(false);

            if (user == null)
            {
                return(TextToImage.EMailToImage("?"));
            }

            if (!user.IsEmailPublic)
            {
                return(TextToImage.EMailToImage("?"));
            }

            return(TextToImage.EMailToImage(user.Email));
        }
        public void InitializeButtons()
        {
            try
            {
                StartButtonIndex       = 0;
                ContinueButtonIndex    = 1;
                ExitGameButtonIndex    = 2;
                ExitProgramButtonIndex = 3;

                int CenterX = Constaints.ScreenResolution.ScreenWidth >> 1;
                int CenterY = Constaints.ScreenResolution.ScreenHeight >> 1;

                Texture2D StartButtonTexture    = new TextToImage("Start Game", DColor.Blue).Image;
                Texture2D ContinueButtonTexture = new TextToImage("Continue Game", DColor.Blue).Image;
                Texture2D ExitGameButtonTexture = new TextToImage("Exit Game", DColor.Blue).Image;
                Texture2D ExitProgramTexture    = new TextToImage("Exit Program", DColor.Blue).Image;

                int ScaleX = (int)(Constaints.ScreenResolution.getScale().X);
                int ScaleY = (int)(Constaints.ScreenResolution.getScale().Y);

                Vector2 StartButtonLocation = new Vector2((CenterX >> 1), CenterY >> 1);
                Vector2 ExitButtonLocation  = new Vector2((CenterX >> 1), CenterY + (CenterY >> 1));

                BStartGame    = new Button(StartButtonLocation, StartButtonTexture.Width * ScaleX, StartButtonTexture.Height * ScaleY, StartButtonTexture);
                BContinuegame = new Button(StartButtonLocation, ContinueButtonTexture.Width * ScaleX, ContinueButtonTexture.Height * ScaleY, ContinueButtonTexture);
                BExitGame     = new Button(ExitButtonLocation, ExitGameButtonTexture.Width * ScaleX, ExitGameButtonTexture.Height * ScaleY, ExitGameButtonTexture);
                BExitProgram  = new Button(ExitButtonLocation, ExitProgramTexture.Width * ScaleX, ExitProgramTexture.Height * ScaleY, ExitProgramTexture);

                buttons = new List <Button>();

                buttons.Add(BStartGame);
                buttons.Add(BContinuegame);
                buttons.Add(BExitGame);
                buttons.Add(BExitProgram);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Calculate the values for the current character
        /// </summary>
        /// <param name="font">font to be used</param>
        public void CalculateValues(Font font)
        {
            // size of the shrunken character to use for the calculation
            const int   Width  = 4;
            const int   Height = 4;
            const float Area   = 16f;

            using (Bitmap bitmap = TextToImage.Convert(this.Character.ToString(), font))
            {
                using (Bitmap shrunk = new Bitmap(Width, Height))
                {
                    using (Graphics g = Graphics.FromImage(shrunk))
                    {
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                        g.Clear(Color.White);

                        g.DrawImage(bitmap, 0, 0, Width, Height);
                    }

                    unsafe
                    {
                        BitmapData data = shrunk.LockBits(
                            new Rectangle(new Point(0, 0), shrunk.Size),
                            ImageLockMode.ReadOnly,
                            PixelFormat.Format24bppRgb);

                        byte *pointer = (byte *)data.Scan0;

                        int padding = data.Stride - (shrunk.Width * 3);

                        int totalValue = 0;

                        for (int y = 0; y < shrunk.Height; y++)
                        {
                            for (int x = 0; x < shrunk.Width; x++)
                            {
                                totalValue += pointer[2];

                                pointer += 3;
                            }

                            pointer += padding;
                        }

                        // store the average value
                        this.Value = (int)(((float)totalValue / Area) + 0.5);

                        int totalDifference = 0;

                        pointer = (byte *)data.Scan0;

                        for (int y = 0; y < shrunk.Height; y++)
                        {
                            for (int x = 0; x < shrunk.Width; x++)
                            {
                                // add the difference between the average value and this pixel
                                totalDifference += this.Value > pointer[2] ? this.Value - pointer[2] : pointer[2] - this.Value;

                                pointer += 3;
                            }

                            pointer += padding;
                        }

                        // store the score for this character
                        this.Score = (int)(((float)totalDifference / Area) + 0.5);

                        shrunk.UnlockBits(data);
                    }
                }
            }
        }
Beispiel #8
0
        public TrackAndLabel(int LineWidth, double Lat, double Lon, string Track_ID, string Label_ID, // This has be a CALLSIGN or ModeA
                            string ModeC)
        {
            // Track data
            Track.Latitude = Lat;
            Track.Longitude = Lon;
            Track.ID = Track_ID;
            if (IconSwitcher == 0)
            Track.IconImage = "icons/Track_Blue.png";
            else
            Track.IconImage = "icons/Track_Pink.png";

            // Label Data
            TextToImage TI = new TextToImage();
            TI.GenerateAndStore(Label_ID + IconSwitcher.ToString(), Label_ID + Environment.NewLine + ModeC, Color.Green);
            Label.ID = Label_ID;
            Label.Draggable = true;
            Label.IconImage = "icons/labels/dynamic/" + Label_ID + IconSwitcher.ToString() + ".png";
            if (IconSwitcher == 0)
                IconSwitcher = 1;
            else
                IconSwitcher = 0;

            // Place the label close the the track symbol factoring in the zoom setting.
            Label.Latitude = Track.Latitude + (0.2 / CustomMap.GetScaleFactor(CurrentZoomLevel));
            Label.Longitude = Track.Longitude - (0.15 / CustomMap.GetScaleFactor(CurrentZoomLevel));

            // Leader line
            Color color = Color.FromName(Color.Green.Name);
            LeaderLine.ColorCode = String.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
            LeaderLine.Width = LineWidth;
            LeaderLine.ID = "L1";
            LeaderLine.Points.Add(Track);
            LeaderLine.Points.Add(Label);

            // Track prediction symbol and line 1
            if (PredictionEngine1_Enabled)
            {
                PredictionSymbol_1 = new GooglePoint();
                PredictionSymbol_1.Latitude = Track.Latitude + 0.050;
                PredictionSymbol_1.Longitude = Track.Longitude + 0.020;
                PredictionSymbol_1.ID = "P1";
                PredictionSymbol_1.IconImage = "icons/Track_Yellow.png";
                color = Color.FromName(Color.Yellow.Name);
                TrackToPredictionLine1.ColorCode = String.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
                TrackToPredictionLine1.ID = "L2";
                TrackToPredictionLine1.Width = LineWidth;
                TrackToPredictionLine1.Points.Add(Track);
                TrackToPredictionLine1.Points.Add(PredictionSymbol_1);
            }

            // Track prediction symbol and line 1
            if (PredictionEngine2_Enabled)
            {
                PredictionSymbol_2 = new GooglePoint();
                PredictionSymbol_2.Latitude = Track.Latitude + 0.060;
                PredictionSymbol_2.Longitude = Track.Longitude + 0.040;
                PredictionSymbol_2.ID = "P2";
                PredictionSymbol_2.IconImage = "icons/Track_Blue.png";
                color = Color.FromName(Color.Blue.Name);
                TrackToPredictionLine2.ColorCode = String.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
                TrackToPredictionLine2.ID = "L3";
                TrackToPredictionLine2.Width = LineWidth;
                TrackToPredictionLine2.Points.Add(Track);
                TrackToPredictionLine2.Points.Add(PredictionSymbol_2);
            }

            // Track prediction symbol and line 1
            if (PredictionEngine3_Enabled)
            {
                PredictionSymbol_3 = new GooglePoint();
                PredictionSymbol_3.Latitude = Track.Latitude + 0.070;
                PredictionSymbol_3.Longitude = Track.Longitude + 0.060;
                PredictionSymbol_3.ID = "P3";
                PredictionSymbol_3.IconImage = "icons/Track_Pink.png";
                color = Color.FromName(Color.Pink.Name);
                TrackToPredictionLine3.ColorCode = String.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
                TrackToPredictionLine3.ID = "L4";
                TrackToPredictionLine3.Width = LineWidth;
                TrackToPredictionLine3.Points.Add(Track);
                TrackToPredictionLine3.Points.Add(PredictionSymbol_3);
            }
        }