{"id":95,"date":"2010-03-25T06:58:10","date_gmt":"2010-03-24T22:58:10","guid":{"rendered":"\/?p=95"},"modified":"2010-03-25T06:58:10","modified_gmt":"2010-03-24T22:58:10","slug":"95","status":"publish","type":"post","link":"https:\/\/www.justzz.com\/spec\/95.html","title":{"rendered":"[C#]\u56fe\u7247\u6dfb\u52a0\u6c34\u5370"},"content":{"rendered":"<p><strong>\/<\/strong>\/\u589e\u52a0\u6c34\u5370\u4e3b\u8981\u65b9\u6cd5<br \/>\nprivate void addWaterMark_Click(object sender, EventArgs e)<br \/>\n{<br \/>\nresults.Text = \"\";<br \/>\nif (this.selFloderValue.Text == \"\")<br \/>\n{<br \/>\nresults.Text += \"\u672a\u9009\u62e9\u6587\u4ef6\u5939\u76ee\u5f55\\n\";<br \/>\nreturn;<br \/>\n}<br \/>\nif (warterMarkValue.Text == \"\")<br \/>\n{<br \/>\nresults.Text += \"\u672a\u8f93\u5165\u6c34\u5370\u6587\u672c\\n\";<br \/>\nreturn;<br \/>\n}<br \/>\n\/\/\u83b7\u53d6\u6240\u6709\u76ee\u5f55<br \/>\nStringBuilder allDirs = new StringBuilder(\"\");<br \/>\nallDirs.Append(this.selFloderValue.Text);<br \/>\ngetAllDirectories(this.selFloderValue.Text, allDirs);<br \/>\nstring[] allDirArr = CmsTool.common.Tool.Tool.split(allDirs.ToString(), \":*\");<br \/>\n\/\/\u83b7\u53d6\u6240\u6709\u56fe\u7247\u6587\u4ef6<br \/>\nforeach (string strDir in allDirArr)<br \/>\n{<br \/>\nstring[] files = Directory.GetFiles(strDir);<br \/>\nforeach (string file in files)<br \/>\n{<br \/>\n\/\/\u589e\u52a0\u6c34\u5370<br \/>\nif (File.Exists(file))<br \/>\n{<br \/>\nif (file.ToLower().EndsWith(\".jpg\") || file.ToLower().EndsWith(\".png\"))<br \/>\n{<br \/>\nSystem.Drawing.Image image = null;<br \/>\nSystem.Drawing.Graphics g = null;<br \/>\ntry<br \/>\n{<br \/>\nstring tmpPath = file + \"Tmp\";<br \/>\n\/\/\u6587\u5b57\u6c34\u5370<br \/>\nimage = System.Drawing.Image.FromFile(file);<br \/>\ng = System.Drawing.Graphics.FromImage(image);<br \/>\ng.DrawImage(image, 0, 0, image.Width, image.Height);<br \/>\nSystem.Drawing.Font f = new System.Drawing.Font(\"Palatino Linotype\", 18);<br \/>\nSystem.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);<br \/>\nstring wmValue = warterMarkValue.Text;<br \/>\n\/\/\u589e\u52a0\u6c34\u5370\u00a0 \u56fe\u7247\u6c34\u5370\u8c03\u7528 g.DrawImage\u65b9\u6cd5<br \/>\ng.DrawString(wmValue, f, b, image.Width - 200, image.Height - 40);<br \/>\ng.Dispose();<br \/>\nimage.Save(tmpPath);<br \/>\nimage.Dispose();<br \/>\nFile.Delete(file);<br \/>\nFile.Move(tmpPath, file);<br \/>\nresults.Text += file + \"\u589e\u52a0\u6c34\u5370\u6210\u529f\\n\";<br \/>\n}<br \/>\ncatch (Exception e1)<br \/>\n{<br \/>\nif (g != null) g.Dispose();<br \/>\nif (image != null) image.Dispose();<br \/>\nresults.Text += file + \"\u589e\u52a0\u6c34\u5370\u5931\u8d25\\n\";<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>\u8c03\u7528GIF\u7b49\u542b\u6709\u7d22\u5f15\u7684\u56fe\u7247\u4f1a\u4ea7\u751f\u5f02\u5e38\u3002<\/p>\n<p>MSDN\u5f15\u7528\uff1a<\/p>\n<p>\u5982\u679c\u56fe\u50cf\u662f\u7d22\u5f15\u50cf\u7d20\u683c\u5f0f\uff0c\u6b64\u65b9\u6cd5\u5c06\u5f15\u53d1\u5f02\u5e38\uff0c\u540c\u65f6\u4ea7\u751f\u4ee5\u4e0b\u6d88\u606f\uff1a\u201c\u65e0\u6cd5\u4ece\u5e26\u6709\u7d22\u5f15\u50cf\u7d20\u683c\u5f0f\u7684\u56fe\u50cf\u521b\u5efa Graphics \u5bf9\u8c61\u3002\u201d\u3002\u4e0b\u9762\u7684\u5217\u8868\u5217\u51fa\u4e86\u5404\u79cd\u7d22\u5f15\u50cf\u7d20\u683c\u5f0f\u3002<\/p>\n<p>Format1bppIndexed<br \/>\nFormat4bppIndexed<br \/>\nFormat8bppIndexed<\/p>\n<p>\u5f53\u56fe\u50cf\u662f\u4ee5\u4e0b\u4efb\u4e00\u50cf\u7d20\u683c\u5f0f\u65f6\uff0c\u6b64\u65b9\u6cd5\u4e5f\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002<\/p>\n<p>Undefined<br \/>\nDontCare<br \/>\nFormat16bppArgb1555<br \/>\nFormat16bppGrayScale<\/p>\n<p>\u4e3a\u91ca\u653e Graphics \u548c\u7531 FromImage \u65b9\u6cd5\u521b\u5efa\u7684\u76f8\u5173\u8d44\u6e90\uff0c\u60a8\u5e94\u8be5\u59cb\u7ec8\u8c03\u7528 Dispose \u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/\u589e\u52a0\u6c34\u5370\u4e3b\u8981\u65b9\u6cd5 private void addWaterMark_Click(object sender, EventArgs e) { results.Text = \"\"; if (this.selFloderValue.Text == \"&hellip;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-t"],"_links":{"self":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":0,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}