0

I'm creating app like snapchat.How to add text on image like snapchat text. Like this

Here is my code :

private void button1_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream(@"path\images.png", FileMode.Open, FileAccess.Read);
        Image image = Image.FromStream(fs);


        SolidBrush drawBrush = new SolidBrush(Color.Black);
        fs.Close();

        Bitmap b = new Bitmap(image);
        Graphics graphics = Graphics.FromImage(b);
        graphics.FillRectangle(Brushes.Red, new Rectangle(10, 10, 2, 2));

        graphics.DrawString("Hello", this.Font, Brushes.Red, 100, 100);


        b.Save(@"path\images.png", image.RawFormat);

        image.Dispose();
        b.Dispose();
    }

Text write on the image working fine but i don't know to write text on image like snapchat.I have idea like first calcualte the string size then set background color of string and opacity etc.But I don't know how,please help me thank you.

Hameed
  • 51
  • 4
  • 16
  • Your code doesn't compile and looks like you incorrectly reposted it here: `graphics.DrawSt` isn't a thing, don't you mean `graphics.DrawString`? Note that the `TextRenderer` class replaces GDI's `DrawString` for better text quality. – Dai Mar 05 '17 at 11:09
  • this code working for text on image . – Hameed Mar 05 '17 at 11:10
  • i have correct it.But in my code graphics.DrawString. – Hameed Mar 05 '17 at 11:12
  • Your code is still wrong - you're using `graphics.DrawString` when you mean `image.Save`. – Dai Mar 05 '17 at 11:13
  • let me again check please – Hameed Mar 05 '17 at 11:24
  • @Dai please check now. – Hameed Mar 05 '17 at 11:32
  • 2
    To measure the text graphics.MeasureString will tell you a size for a font. To write cnetered into a recantlge use another DrawString overload which takes a rectangle plus a centered textformat.. So you need one extra line and one line changed a bit. getting close ;-) – TaW Mar 05 '17 at 11:39
  • @TaW please I'm beginner and i don't know how to do it :( Please can you do it in my code please please sir :( :( – Hameed Mar 05 '17 at 12:18

0 Answers0