C#根据原始图像改变水印图像大小

时间:2013-05-02 07:34:10

标签: c# image watermark

我在上传之前正在为我的图片加水印。 面临的问题是如果图像很小,水印看起来很大.. 我想根据原始图像改变水印图像大小..

例如:水印图像应为原始图像的30%。 我在c#中执行此操作:

  

imageGraphics.FillRectangle(watermarkBrush,new Rectangle(new Point(x,y),new Size(watermarkImage.Width + 1,watermarkImage.Height)));

我应该做些什么才能先获得图像尺寸,然后相应地更改水印图像尺寸?

2 个答案:

答案 0 :(得分:2)

那么......就像:

Bitmap yourImage = ...;
Bitmap yourWatermark = ...;

int newWaterWidth = (int)((float)yourImage.Width * .3);
int newWaterHeight = (int)((float)yourImage.Height* .3);


using(Bitmap resizedWaterm = new Bitmap(newWaterWidth, newWaterHeight))
using(Graphics g = Graphics.FromImage((Image)resizedWaterm))
{
  g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  g.DrawImage(yourWatermark, 0, 0, newWaterWidth , newWaterHeight );
}

int x = ..., y = ...;
using(Graphics g2 = Graphics.FromImage((Image)resizedWaterm))
{
  g2.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height)));
}

(未经测试,您还需要在......点填写值)

调整大小的代码:Resizing an Image without losing any quality

希望这有帮助!

答案 1 :(得分:0)

NReco.VideoConverter.FFMpegConverter ffMpeg = new NReco.VideoConverter.FFMpegConverter();

pod 'SwiftyRSA', :git => 'git@github.com:TakeScoop/SwiftyRSA.git', :branch => 'swift-2.3'