private void btn_start_Click(object sender, EventArgs e) { Image img = Image.FromFile("Картинка.jpg"); picture.Width = img.Width; picture.Height = img.Height; this.Width = picture.Width + 40; this.Height = picture.Height + 75; using (Graphics g = Graphics.FromImage(img)) { Font font = new Font("Verdana", 30); Font font2 = new Font("Verdana", 16); g.DrawString("Счастье - когда прошлое не", font, Brushes.White, 93, 440); g.DrawString("напрягает, настоящее не беспокоит, а будущее впечатляет!", font2, Brushes.White, 60, 490); } picture.Image = img; img.Save("result.jpg", ImageFormat.Jpeg); } 

How to make it so that you can choose the font and color of the text and write at any point in the picture, as in Photoshop? fontDialog, colorDialog tried but did not understand to embed it in the graphics. Thanks in advance thanks. If something is not clearly written, I will try to tell you more!

    1 answer 1

    You need to use the FontDialog.Font and FontDialog.Color . currentFont and currentColor fields, initialize them with some default values ​​and fill in the dialog if necessary.

     private void btnSelectFont_Click(object sender, EventArgs e) { fontDialog.ShowColor = true; if (fontDialog.ShowDialog() != DialogResult.Cancel) { сurrentFont = fontDialog.Font; сurrentColor = fontDialog.Color; } } 

    And then use them in your code:

     private void btn_start_Click(object sender, EventArgs e) { ... using (Graphics g = Graphics.FromImage(img)) { g.DrawString("...", currentFont, new SolidBrush(currentColor), 93, 440); g.DrawString("...", currentFont, new SolidBrush(currentColor), 60, 490); } ... } 
    • Thanks buddy bailed out))) I wanted to do it, but I got up in a stupor. Thanks again - Sergey_73
    • @ Sergey_73 is not at all. - andreycha