Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've found some source to write an text on image.
But I don't have any knowladge about graphic class.
So can somebody help me to get the font size bigger?
Here is my source code

C#
private void write_text_on_image(string image_path)
        {
            var bmp = Bitmap.FromFile(image_path);
            var newImage = new Bitmap(bmp.Width, bmp.Height + 50);

            var gr = Graphics.FromImage(newImage);
            gr.DrawImageUnscaled(bmp, 0, 0);

            gr.DrawString("This is added text", SystemFonts.DefaultFont, Brushes.Black,
           
                new RectangleF(0, bmp.Height-450, bmp.Width-300, 50));
            string new_img_path = image_path.Replace("_1", "_2");
            newImage.Save(new_img_path);
            newImage.Dispose();
            bmp.Dispose();
            delete_old_img(image_path);
        }


What I have tried:

Used "SystemFonts.CaptionFont" instead of SystemFonts.DefaultFont"
Posted
Updated 23-May-16 5:11am

Rather than DefaultFont create a Font of the family and size you want

C#
Font f = new Font(new FontFamily("Verdana"), 10);


And use that font object (f) in DrawString instead of DefaultFont
 
Share this answer
 
Comments
hapiten 23-May-16 21:21pm    
Thank you very much
Try to create your own font. See Font Class (System.Drawing)[^]

Preferably you have a private member variable and create the object in the constructor.
C#
private Font myFont;

public MyClassName()
{
    myFont = new Font("Arial", 14.0F, FontStyle.Bold);
}


C#
private void write_text_on_image(string image_path)
{
...
    gr.DrawString("This is added text", myFont, Brushes.Black, ...);
...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900