0
我想對圖像應用水印。白條,然後文字水印?
此刻,我想利用這個代碼,但它的失敗對不同大小的圖像:
public void AddWaterMark(string filePath, string watermarkText)
{
Image img = Image.FromFile(
MapPath(GlobalVariables.UploadPath + "/" + filePath));
Graphics gr = Graphics.FromImage(img);
Font font = new Font("Alial Black", 40);
Color color = Color.FromArgb(50, 241, 235, 105);
StringFormat stringFormat = new StringFormat
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Near
};
gr.SmoothingMode = SmoothingMode.AntiAlias;
gr.DrawString(watermarkText, font, new SolidBrush(color),
new Point(20, img.Height - 60), stringFormat);
img.Save(MapPath(GlobalVariables.UploadPath + "/w_" + filePath));
}
有時字體熄滅底部。我希望它是沿着圖像底部的文字。
我如何確保它不會脫離底部?
此外,我想稍微加強它。我想在圖像底部的整個長度上製作一個白色但透明的條,然後在其上寫入黑色文本。這可能與繪圖?因此,橫跨圖像底部的一個橫條,可能高60個像素,而在60像素的中間,我想要寫入文本(左對齊)。
我也發現文本招式arounf,具體取決於文件大小
下面是工作的一個形象:有時 http://www.listerhome.com/fulldisplay.aspx?imageid=100055
布爾,當我上載更高分辨率的圖像,我得到這個: http://www.listerhome.com/fulldisplay.aspx?imageid=100060
這增加了一個矩形,這是非常有用的,謝謝。但是我發現在較大的圖像上,字體比加載較小圖像時要大。 – Craig 2011-12-28 08:14:39
你可以發佈圖片樣本(大和小)? – 2011-12-28 11:43:58
我可以提供我的測試網站的網址嗎? – Craig 2011-12-28 12:06:52