Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm building a site for a photographer who wants to sell his work online. To prevent people simply right clicking on the image and choosing save as we're going to "watermark" each image with the website address.

 

Is there any easy way to do this automatically using the image classes?

 

Thanks

  • Leaders
Posted

There is no incredibly quick and easy way to do this, but with some effort you should be able to write a program to automate this process and perform batch-processing. You would have to use the Image class in conjunction with the Graphics class. The process would not really be reversible (you would naturally want to keep the originals) and there might be loss of image quality.

 

  • Assuming all the files are in the same folder, you would start by asking the user which folder the files are found in. I'm guessing that the images would be JPEGs. You can use the Directory.GetFiles method and specify a file pattern (i.e. "*.jpeg;*.jpg" but I'm not positive about the format) to get a string array containing filenames.
  • Loop through the files, opening them with the Bitmap constructor. Use the Graphics.FromImage function to create a Graphics object which can manipulate the image.
  • You can simply write some text to the image (Graphics.DrawString), use a pre-prepared semi-transparent image (Graphics.DrawImage), or use a pre-prepared but not semi-transparent image and use a color matrix to render the image semi-transparent.
  • After watermarking the image, save it. To optimize image quality and file size, you will probably want to enumerate image saving codecs to find the JPEG codec, with which you can specify the image quality (I can help you with this).
  • Dispose of the image and Graphics objects.
  • Repeat.

 

Hope that helps, and I'll be glad to help out if you hit some bumps along the way.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...