.net 加水印 图片变大很多 解决方法
/// 给图片加水印 中国红木网
/// </summary>
/// <param name="originalImg"></param>
/// <param name="waterImg"></param>
/// <param name="trbl"></param>
/// <returns></returns>
public
static
Image WatermarkImage(Image originalImg, Image waterImg, WatermarkTRBL trbl)
{
Image image = (Image)originalImg.Clone();
using
(Graphics g = Graphics.FromImage(image))
{
Rectangle r =
new
Rectangle();
r.Height = waterImg.Height;
r.Width = waterImg.Width;
if
(trbl.Top !=
null
)
{
r.Y = (
int
)trbl.Top;
}
if
(trbl.Right !=
null
)
{
r.X = originalImg.Width - waterImg.Width - (
int
)trbl.Right;
}
if
(trbl.Bottom !=
null
)
{
r.Y = originalImg.Height - waterImg.Height - (
int
)trbl.Bottom;
}
if
(trbl.Left !=
null
)
{
r.X = (
int
)trbl.Left;
}
g.DrawImage(waterImg, r, 0, 0, waterImg.Width, waterImg.Height, GraphicsUnit.Pixel);
}
return
image;
}
Bitmap b = new Bitmap(image.Width,
image.Height,PixelFormat.Format24bppRgb);
Graphics g =
Graphics.FromImage(b);
g.Clear(Color.White);
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.Default;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
g.DrawImage(image, 0, 0, image.Width, image.Height);
高质量 用普通模式
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。