asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧_asp.net教程-查字典教程网
asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧
asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧
发布时间:2016-12-29 来源:查字典编辑
摘要:publicclassMyGDI{publicstaticvoidCreateWatermark(stringsSrcFilePath,st...

publicclassMyGDI

{

publicstaticvoidCreateWatermark(stringsSrcFilePath,stringsDstFilePath,stringsText1,stringsColor1,stringsSize1,stringsFont1,stringsText2,stringsColor2,stringsSize2,stringsFont2,stringsBgColor,stringsTransparence)

{

System.Drawing.Imageimage=System.Drawing.Image.FromFile(sSrcFilePath);

Graphicsg=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);

Fontf1=newFont(sFont1,float.Parse(sSize1));

Fontf2=newFont(sFont2,float.Parse(sSize2));

Brushbrushfortext1=newSolidBrush(ColorTranslator.FromHtml(sColor1));

Brushbrushfortext2=newSolidBrush(ColorTranslator.FromHtml(sColor2));

Brushbrushforbg=newSolidBrush(Color.FromArgb(Convert.ToInt16(255*float.Parse(sTransparence)),ColorTranslator.FromHtml(sBgColor)));

g.RotateTransform(-20);

Rectanglerect=newRectangle(-image.Width/2-50,image.Height-50,image.Width*2,40);

g.DrawRectangle(newPen(brushforbg),rect);

g.FillRectangle(brushforbg,rect);

Rectanglerectfortext1=newRectangle(-image.Width/2+image.Width/5,image.Height-45,image.Width*2,60);

for(inti=0;i<10;i++)

g.DrawString(sText1,f1,brushfortext1,rectfortext1);

Rectanglerectfortext2=newRectangle(-image.Width/2+image.Width/5,image.Height-25,image.Width*2,60);

for(inti=0;i<10;i++)

g.DrawString(sText2,f2,brushfortext2,rectfortext2);

image.Save(sDstFilePath,ImageFormat.Jpeg);

image.Dispose();

}

publicstaticvoidCreateRoundedCorner(stringsSrcFilePath,stringsDstFilePath,stringsCornerLocation)

{

System.Drawing.Imageimage=System.Drawing.Image.FromFile(sSrcFilePath);

Graphicsg=Graphics.FromImage(image);

g.SmoothingMode=SmoothingMode.HighQuality;

g.InterpolationMode=InterpolationMode.HighQualityBicubic;

g.CompositingQuality=CompositingQuality.HighQuality;

Rectanglerect=newRectangle(0,0,image.Width,image.Height);

GraphicsPathrectPath=CreateRoundRectanglePath(rect,image.Width/10,sCornerLocation);//构建圆角外部路径

Brushb=newSolidBrush(Color.White);//圆角背景白色

g.DrawPath(newPen(b),rectPath);

g.FillPath(b,rectPath);

g.Dispose();

image.Save(sDstFilePath,ImageFormat.Jpeg);

image.Dispose();

}

publicstaticvoidCreatePlainText(stringsSrcFilePath,stringsDstFilePath,stringsText,stringsColor,stringsSize,stringsFont)

{

System.Drawing.Imageimage=System.Drawing.Image.FromFile(sSrcFilePath);

Graphicsg=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;//文字抗锯齿

Fontf=newFont(sFont,float.Parse(sSize));

Brushb=newSolidBrush(ColorTranslator.FromHtml(sColor));

Rectanglerect=newRectangle(10,5,image.Width,image.Height);//适当空开一段距离

for(inti=0;i<30;i++)//加强亮度

g.DrawString(sText,f,b,rect);

image.Save(sDstFilePath,ImageFormat.Jpeg);

image.Dispose();

}

privatestaticGraphicsPathCreateRoundRectanglePath(Rectanglerect,intradius,stringsPosition)

{

GraphicsPathrectPath=newGraphicsPath();

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;

}

}

returnrectPath;

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新asp.net教程学习
    热门asp.net教程学习
    编程开发子分类