Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:59:14+00:00 2026-05-27T17:59:14+00:00

I’m making a batch watermarking tool for myself and some others at work and

  • 0

I’m making a batch watermarking tool for myself and some others at work and using the following code allows me to annotate text on the bottom right of the image but I’m not able to make it annotate on the bottom left without manually adjusting the coordinates which differs for any given image. Also changing StringAlignment.Far to StringAlignment.Near etc doesn’t do anything but possibly annotate the text outside the image somewhere that doesn’t show up.

MSDN has some explanation but it is not helping me. Any help would be great I’ve been fighting this for some time now.

private void button1_Click(object sender, EventArgs e)
{
    foreach (string images in Directory.GetFiles(textBox1.Text))
    {
        System.Drawing.Image img = System.Drawing.Image.FromFile(images);

        Graphics gr = Graphics.FromImage(img);

        Font font = new Font("Times New Roman", (float)25, 
            System.Drawing.FontStyle.Regular);
        System.Drawing.Color color = System.Drawing.Color.Red;

        StringFormat stringFormat = new StringFormat();
        stringFormat.Alignment = StringAlignment.Far;
        stringFormat.LineAlignment = StringAlignment.Far;

        gr.SmoothingMode = SmoothingMode.AntiAlias;

        gr.DrawString("WATERMARK GOES HERE"+ images, font, 
            new System.Drawing.SolidBrush(color), 
            new System.Drawing.Point(img.Width - 0, img.Height - 0), 
            stringFormat);

        MemoryStream outputStream = new MemoryStream();
        img.Save(images+"Stamped.jpg");
    }

    MessageBox.Show("done");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:59:15+00:00Added an answer on May 27, 2026 at 5:59 pm
    • Name your controls. Don’t use “button1”, “textbox1”, etc.
    • Use the “using” statement. Writing “System.Drawing.Point” and other fully qualified names just increases the size of your code and makes it harder to read.
    • You are creating a new instance of a SolidBrush class for each image you are watermarking. You should create the brush before the loop and just use it in the loop, then dispose of it afterwards.
    • Your declaration of a MemoryStream does nothing and is used nowhere.

    As for the watermarking itself, you should decide if you want it to scale with image size, or to be a consistent size. Or you can have it have a maximum/minimum size. That’s your preference.

    private void watermark_btn_Click(object sender, EventArgs e)
    {
        string watermarkText = "ShowThisWatermark";
    
        using (Font font = new Font("Times New Roman", (float)25, FontStyle.Regular))
        using (SolidBrush brush = new SolidBrush(Color.Red))
        foreach (string file in Directory.GetFiles(directory_txt.Text))
        {
            try
            {
                Bitmap b = new Bitmap(file);
    
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
    
                    SizeF measuredSize = g.MeasureString(watermarkText, font);
    
                    // Use this to watermark the bottom-left corner
                    g.DrawString(watermarkText, font, brush, 0, b.Height - measuredSize.Height);
    
                    // Use this to watermark the bottom-right corner
                    g.DrawString(watermarkText, font, brush, b.Width - measuredSize.Width, b.Height - measuredSize.Height);
                }
    
                b.Save(Path.GetFileNameWithoutExtension(file) + "_stamped" + Path.GetExtension(file));
            }
            catch
            {
                continue;
            }
        }
    }
    

    The try/catch is a lazy way of skipping files which aren’t images. Since Directory.GetFiles returns all files in the directory, a non-image file would cause an exception. This could be done in a much neater fashion, but since that was not the nature of your question I kept it simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.