protected void Button1_Click(object sender, EventArgs e) { FileName = Guid.NewGuid().ToString(); FilePath = @"C:\Users\bravemountravi\Desktop\Image\Attachments\" + FileName + "." + "jpg"; System.Drawing.Image Mainimg = System.Drawing.Image.FromFile(@"C:\Users\travi\Desktop\Image\Attachments\funny-dog-wallpaper-and-picture-p0d-funny-dog-photo-hd-ahhw.jpg"); System.Drawing.Image img2 = System.Drawing.Image.FromFile(@"C:\Users\travi\Desktop\Image\Images\watermark3.png"); Graphics g = Graphics.FromImage(Mainimg); double _scalefactor = (Mainimg.Width / 4800.0); if (_scalefactor <= 0.1) { _scalefactor = 0.1; } else if (_scalefactor <= 0.2) { _scalefactor = 0.2; } else if (_scalefactor >= 1) { _scalefactor = 1.0; } double _newwidth = (_scalefactor * img2.Width); //double _newHeight = ((_newwidth / img2.Width) * (img2.Height)); double _newHeight = (_scalefactor * img2.Height); Bitmap bitimg = WaterMarkScaleImage(img2, Convert.ToInt32(Math.Round(_newwidth, 0)), Convert.ToInt32(Math.Round(_newHeight, 0))); System.Drawing.Image scaleimg = (System.Drawing.Image)bitimg; int left = Mainimg.Width - scaleimg.Width; int top = Mainimg.Height - scaleimg.Height; g.DrawImage(scaleimg, left, top, scaleimg.Width, scaleimg.Height); g.Dispose(); Mainimg.Save(FilePath); } public Bitmap WaterMarkScaleImage(System.Drawing.Image image, int maxWidth, int maxHeight) { var newImage = new Bitmap(maxWidth, maxHeight); Graphics.FromImage(newImage).DrawImage(image, 0, 0, maxWidth, maxHeight); Bitmap bmp = new Bitmap(image); return bmp; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)