3

I have a bunch of photos at home that I'd like to add a time and date stamp to based on the file properties.

I'll be writing this as a WPF application but does anyone have sample c# code on how to add text to a .jpg file in the bottom right hand corner of the photo?

I know there are a couple of libraries out there but would like to actually have the c# code itself as I can see a few applications of that here at Muppet Labs plus it'd be nice to learn this also.

EDIT

Thanks to Andy for the link. I have posted my code here for others to see the solution.

    System.Drawing.Image img = System.Drawing.Image.FromFile("Brush Tail Possum.jpg");
    System.Drawing.Image imgOverlay = System.Drawing.Image.FromFile("overlay.png");
    Graphics gr = Graphics.FromImage(img);

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

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

    gr.SmoothingMode = SmoothingMode.AntiAlias;

    gr.DrawImage(imgOverlay, new System.Drawing.Point(img.Width - 78, img.Height - 25));
    gr.DrawString(DateTime.Now.ToShortDateString(), font, new System.Drawing.SolidBrush(color), new System.Drawing.Point(img.Width - 40, img.Height - 15), stringFormat);

    MemoryStream outputStream = new MemoryStream();
    img.Save("Brush Tail Possum2.jpg");

Overlay.png is a small image that sits under the text and aids in readability.

griegs
  • 22,624
  • 33
  • 128
  • 205

1 Answers1

2

Found this question that has example code for adding a watermark to jpgs any use?

Community
  • 1
  • 1
Andy Robinson
  • 7,309
  • 2
  • 30
  • 20
  • +1 Ah, that's excellent. Didn't search on "watermark" is the problem here. :) – griegs Sep 27 '11 at 23:21
  • Yep, that was the exact answer I was looking for thanks. A few mods and i have a great little application for the wife! :) thanks again – griegs Sep 28 '11 at 00:42