Found on the codeproject class to insert a diagonal watermark on the image. Everything is fine, although the size of the image from 150kb increases to 600kb. If I manually put this sign - increases by 30-40kb.

 public class WaterMark { private string waterMarkText; private string fontName; private FontStyle fontStyle; private Color color; private int maxFontSize; public WaterMark(string waterMarkText, string fontName, int maxFontSize, FontStyle fontStyle, Color color, byte alpha) { this.waterMarkText = waterMarkText; this.fontName = fontName; this.fontStyle = fontStyle; this.color = Color.FromArgb(alpha, color); this.maxFontSize = maxFontSize; } public Bitmap Apply(string url) { Bitmap bmp; using(Bitmap newBitmap = new Bitmap(url)) using(Graphics g = Graphics.FromImage(newBitmap)) { double tangent = (double) newBitmap.Height / (double) newBitmap.Width; double angle = Math.Atan(tangent) * (180 / Math.PI); double halfHypotenuse = Math.Sqrt((newBitmap.Height * newBitmap.Height) + (newBitmap.Width * newBitmap.Width)) / 2; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; Font font = new Font(fontName, maxFontSize, fontStyle); for (int i = maxFontSize; i > 0; i--) { font = new Font(fontName, i, fontStyle); SizeF sizef = g.MeasureString(waterMarkText, font, int.MaxValue); double sin = Math.Sin(angle * (Math.PI / 180)); double cos = Math.Cos(angle * (Math.PI / 180)); double opp1 = sin * sizef.Width; double adj1 = cos * sizef.Height; double opp2 = sin * sizef.Height; double adj2 = cos * sizef.Width; if (opp1 + adj1 < newBitmap.Height && opp2 + adj2 < newBitmap.Width) { break; } } g.SmoothingMode = SmoothingMode.None; g.RotateTransform((float) angle); g.DrawString(waterMarkText, font, new SolidBrush(color), new Point((int) halfHypotenuse, 0), stringFormat); bmp = new Bitmap(newBitmap); newBitmap.Dispose(); } return bmp; } } 
  • Try to download irfanview and compare the characteristics of the image that you saved with your own hands and which you saved through the program. I suspect that the characteristics of the image changes your code. - iluxa1810
  • What is the format of the input and output image file? For some formats this is critical - rdorn

0