public class MyGDI
{
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); //构建圆角外部路径
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); //适当空开一段距离
for (int i = 0; i < 30; i++) //加强亮度
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;
}
}
{
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); //构建圆角外部路径
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); //适当空开一段距离
for (int i = 0; i < 30; i++) //加强亮度
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;
}
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。