{"id":308,"date":"2011-12-01T21:48:24","date_gmt":"2011-12-01T11:48:24","guid":{"rendered":"http:\/\/www.reenadu.com\/?p=308"},"modified":"2011-12-01T21:48:24","modified_gmt":"2011-12-01T11:48:24","slug":"add-watermark-in-your-photo-using-c","status":"publish","type":"post","link":"https:\/\/nickdu.com\/?p=308","title":{"rendered":"Add watermark in your photo using C#"},"content":{"rendered":"<p>Some of my photos need to be added watermark to prevent abusing. I just found a easy way to add watermark into your photo using C#. Here is the code to share.<\/p>\n<pre lang=\"CSharp\">private void button1_Click(object sender, System.EventArgs e)\n{\n\tOpenFileDialog of = new OpenFileDialog();\n\tof.Filter = \"Image Files (*.bmp;*.emf;*.exif;*.gif;*.jpg;*.png;*.tif;*.wmf)|*.bmp;*.emf;*.exif;*.gif;*.jpg;*.png;*.tif;*.wmf\";\n\n\tif(of.ShowDialog(this) == DialogResult.OK)\n\t{\n\t\tImage image = Image.FromFile(of.FileName);\n\t\tGraphics g = Graphics.FromImage(image);\n\n\t\t\/\/ Create a solid brush to write the watermark text on the image\n\t\tBrush myBrush = new SolidBrush(Color.Black);\n\t\tFont myFont = this.Font;\n\t\t\/\/ Calculate the size of the text\n\t\tSizeF sz = g.MeasureString(\"http:\/\/www.nickdu.com\", myFont);\n\n\t\t\/\/ drawing position (X,Y)\n\t\tfloat X =(image.Width - sz.Width)\/2f;\n\t\tfloat Y = image.Height\/2f;\n\n\t\tg.DrawString(\"http:\/\/www.nickdu.com\",myFont,myBrush,X,Y);\n\t\tSaveFileDialog sf = new SaveFileDialog();\n\t\tsf.Filter = of.Filter;\n\t\tif(sf.ShowDialog(this) == DialogResult.OK)\n\t\t{\n\t\t\timage.Save(sf.FileName);\n\t\t}\n\t\timage.Dispose();\n\t}\n}<\/pre>\n<p>This is the sample<\/p>\n<figure id=\"attachment_309\" aria-describedby=\"caption-attachment-309\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.nickdu.com\/wp-content\/uploads\/2011\/12\/1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-309\" title=\"watermark sample\" src=\"http:\/\/www.nickdu.com\/wp-content\/uploads\/2011\/12\/1-300x225.jpg\" alt=\"watermark sample\" width=\"300\" height=\"225\" \/><\/a><figcaption id=\"caption-attachment-309\" class=\"wp-caption-text\">watermark sample<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Some of my photos need to be added watermark to prevent abusing. I just found a easy way to add watermark into your photo using C#. Here is the code to share. private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.Filter = &#8220;Image Files (*.bmp;*.emf;*.exif;*.gif;*.jpg;*.png;*.tif;*.wmf)|*.bmp;*.emf;*.exif;*.gif;*.jpg;*.png;*.tif;*.wmf&#8221;; if(of.ShowDialog(this) == DialogResult.OK) { Image image &hellip; <a href=\"https:\/\/nickdu.com\/?p=308\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Add watermark in your photo using C#&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2],"tags":[],"class_list":["post-308","post","type-post","status-publish","format-standard","hentry","category-net","category-it"],"_links":{"self":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308"}],"version-history":[{"count":0,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}