asp.net下GDI+的一些常用應(yīng)用(水印,文字,圓角處理)技巧
{
public static void CreateWatermark(string sSrcFilePath, string sDstFilePath, string sText1, string sColor1, string sSize1, string sFont1, string sText2, string sColor2, string sSize2, string sFont2, string sBgColor, string sTransparence)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(sSrcFilePath);
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; //文字抗鋸齒
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f1 = new Font(sFont1, float.Parse(sSize1));
Font f2 = new Font(sFont2, float.Parse(sSize2));
Brush brushfortext1 = new SolidBrush(ColorTranslator.FromHtml(sColor1));
Brush brushfortext2 = new SolidBrush(ColorTranslator.FromHtml(sColor2));
Brush brushforbg = new SolidBrush(Color.FromArgb(Convert.ToInt16(255 * float.Parse(sTransparence)), ColorTranslator.FromHtml(sBgColor)));
g.RotateTransform(-20);
Rectangle rect = new Rectangle(-image.Width/2-50, image.Height - 50, image.Width * 2, 40);
g.DrawRectangle(new Pen(brushforbg), rect);
g.FillRectangle(brushforbg, rect);
Rectangle rectfortext1 = new Rectangle(-image.Width/2 + image.Width / 5, image.Height - 45, image.Width * 2, 60);
for (int i = 0; i < 10; i++)
g.DrawString(sText1, f1, brushfortext1, rectfortext1);
Rectangle rectfortext2 = new Rectangle(-image.Width / 2 + image.Width / 5, image.Height -25, image.Width * 2, 60);
for (int i = 0; i < 10; i++)
g.DrawString(sText2, f2, brushfortext2, rectfortext2);
image.Save(sDstFilePath, ImageFormat.Jpeg);
image.Dispose();
}
public static void CreateRoundedCorner(string sSrcFilePath, string sDstFilePath, string sCornerLocation)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(sSrcFilePath);
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
GraphicsPath rectPath = CreateRoundRectanglePath(rect, image.Width / 10, sCornerLocation); //構(gòu)建圓角外部路徑
Brush b = new SolidBrush(Color.White);//圓角背景白色
g.DrawPath(new Pen(b), rectPath);
g.FillPath(b, rectPath);
g.Dispose();
image.Save(sDstFilePath, ImageFormat.Jpeg);
image.Dispose();
}
public static void CreatePlainText(string sSrcFilePath, string sDstFilePath,string sText, string sColor, string sSize, string sFont)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(sSrcFilePath);
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawImage(image, 0, 0, image.Width, image.Height);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; //文字抗鋸齒
Font f = new Font(sFont,float.Parse(sSize));
Brush b = new SolidBrush(ColorTranslator.FromHtml(sColor));
Rectangle rect = new Rectangle(10, 5, image.Width, image.Height); //適當(dāng)空開一段距離
for (int i = 0; i < 30; i++) //加強(qiáng)亮度
g.DrawString(sText, f, b, rect);
image.Save(sDstFilePath, ImageFormat.Jpeg);
image.Dispose();
}
private static GraphicsPath CreateRoundRectanglePath(Rectangle rect, int radius, string sPosition)
{
GraphicsPath rectPath = new GraphicsPath();
switch (sPosition)
{
case "TopLeft":
{
rectPath.AddArc(rect.Left, rect.Top, radius * 2, radius * 2, 180, 90);
rectPath.AddLine(rect.Left, rect.Top, rect.Left, rect.Top + radius);
break;
}
case "TopRight":
{
rectPath.AddArc(rect.Right - radius * 2, rect.Top, radius * 2, radius * 2, 270, 90);
rectPath.AddLine(rect.Right, rect.Top, rect.Right - radius, rect.Top);
break;
}
case "BottomLeft":
{
rectPath.AddArc(rect.Left, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
rectPath.AddLine(rect.Left, rect.Bottom - radius, rect.Left, rect.Bottom);
break;
}
case "BottomRight":
{
rectPath.AddArc(rect.Right - radius * 2, rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90);
rectPath.AddLine(rect.Right - radius, rect.Bottom, rect.Right, rect.Bottom);
break;
}
}
return rectPath;
}
}
- C#(.net)水印圖片的生成完整實(shí)例
- Asp.net 文件上傳類(取得文件后綴名,保存文件,加入文字水印)
- asp.net下用Aspose.Words for .NET動(dòng)態(tài)生成word文檔中的圖片或水印的方法
- asp.net 添加水印的代碼(已測(cè)試)
- .net生成縮略圖及水印圖片時(shí)出現(xiàn)GDI+中發(fā)生一般性錯(cuò)誤解決方法
- asp.net文件上傳功能(單文件,多文件,自定義生成縮略圖,水印)
- .net c# gif動(dòng)畫如何添加圖片水印實(shí)現(xiàn)思路及代碼
- asp.net如何在圖片上加水印文字具體實(shí)現(xiàn)
- Asp.net簡(jiǎn)單實(shí)現(xiàn)給圖片增加文字水印
- .NET生成水印更好的方法實(shí)例代碼
相關(guān)文章
.NET中如何將文本文件的內(nèi)容存儲(chǔ)到DataSet
大家在項(xiàng)目中比較多的會(huì)對(duì)文件進(jìn)行操作,例如文件的上傳下載,文件的壓縮和解壓等IO操作。而在.NET項(xiàng)目中較多的會(huì)使用DataSet,DataTable進(jìn)行數(shù)據(jù)的緩存。每一個(gè)DataSet都是一個(gè)或多個(gè)DataTable對(duì)象的集合,本文主要介紹的是如何將文本文件的內(nèi)容存儲(chǔ)到DataSet里去。2016-12-12asp.net上傳execl文件后,在頁(yè)面上加載顯示(示例代碼)
本篇文章主要是對(duì)asp.net上傳execl文件后,在頁(yè)面上加載顯示(示例代碼)進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02WPF實(shí)現(xiàn)左右移動(dòng)(晃動(dòng))動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)左右移動(dòng)或晃動(dòng)動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12ASP.NET Core WebAPI實(shí)現(xiàn)本地化(單資源文件)
這篇文章主要介紹了ASP.NET Core WebAPI實(shí)現(xiàn)本地化(單資源文件),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06.NET 6開發(fā)TodoList應(yīng)用之實(shí)現(xiàn)查詢排序
這篇文章主要介紹了如何通過(guò).NET 6實(shí)現(xiàn)查詢排序功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí).NET 6有一定的幫助,感興趣的同學(xué)可以了解一下2022-01-01ASP.NET小結(jié)之MVC, MVP, MVVM比較以及區(qū)別(二)
上一篇得到大家的關(guān)注,非常感謝。由于自己對(duì)于這些模式的理解也是有限,對(duì)于MVC,MVP,MVVM這些模式的比較,是結(jié)合自己的理解,一些地方不一定準(zhǔn)確,需要的朋友可以參考下2014-05-05使用Aspose.Cells實(shí)現(xiàn)導(dǎo)入導(dǎo)出
這篇文章主要為大家詳細(xì)介紹了如何使用Aspose.Cells實(shí)現(xiàn)導(dǎo)入導(dǎo)出,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12asp.net服務(wù)器端指令include的使用及優(yōu)勢(shì)介紹
將指定文件的內(nèi)容插入 ASP.NET 文件中,包括網(wǎng)頁(yè)(.aspx 文件)、用戶控件文件(.ascx 文件)和 Global.asax 文件2013-04-04.Net插件框架Managed Extensibility Framework簡(jiǎn)介
這篇文章介紹了.Net插件框架Managed Extensibility Framework,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07