0

I'm watermarking my images before uploading. the problem im facing is if the image is small, the watermark looks to big.. i want to change watermark image size according to the original image..

for e.g. : watermark image should be 30% of the original image. I'm doing this in c#:

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

What am i supposed to do to first get image size and then change watermark image size accordingly ??

Storm
  • 684
  • 9
  • 20
  • 1
    Well... How are you applying the watermark? The `Image` object family have `.Width` and `.Height` values - so you need to do a simple scaling operation which preserves aspect ration and use that when you watermark but without code we won't be able to help – Basic May 02 '13 at 07:44
  • @Basic for watermarking : imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height))); – supriya salunkhe May 02 '13 at 07:48

2 Answers2

2

Well then...something like:

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)));
}

(Not tested, you also need to fill in values at the ... dots)

Code for resizing from: Resizing an Image without losing any quality

Hope this helps!

Community
  • 1
  • 1
mortb
  • 9,361
  • 3
  • 26
  • 44
0

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

            string pathToVideoFile = "D:\\Projects\\Project\\Db_Script\\TAR_Dummy\\TAR_Dummy\\Videos\\"+postedFile.FileName;
            string imagePath = "D:\\Watermarks\\30.png";
            string Id = Guid.NewGuid().ToString();

            //Convert videos from one format to another
            ffMpeg.ConvertMedia(pathToVideoFile, "D:\\Watermarks\\"+Id+".flv", Format.flv);

            //Add Aatermark to videos
            ffMpeg.Invoke("-i "+pathToVideoFile+ " -i "+ imagePath + " -filter_complex \"overlay=10:10\" D:\\Watermarks\\Images\\" + Id+".mp4");

            //Get video thumbnail
            ffMpeg.GetVideoThumbnail(pathToVideoFile, "D:\\Watermarks\\Images\\" + Id.Substring(Id.Length-5)+".jpg");
aaaa
  • 1