("Elisy.NetBridge4"); AddIn = New("AddIn.ElisyNetBridge4"); net = AddIn.GetNet(); net.LoadAssembly("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
() (.) ...().(); = (); .(); ;
bytes = net.CallStatic("System.Convert", "FromBase64String", Base64String()); bitmap = net.New("System.Drawing.Bitmap", net.New("System.IO.MemoryStream", bytes));
outputBitmap = net.New("System.Drawing.Bitmap", width, height); g = net.CallStatic("System.Drawing.Graphics", "FromImage", outputBitmap); g.CompositingQuality = net.New("System.Drawing.Drawing2D.CompositingQuality").HighQuality; g.SmoothingMode = net.New("System.Drawing.Drawing2D.SmoothingMode").HighQuality; g.InterpolationMode = net.New("System.Drawing.Drawing2D.InterpolationMode").HighQualityBicubic; g.Clear(net.GetStatic("System.Drawing.Color", "WhiteSmoke")); sx = width / Bitmap.Width; sy = height / Bitmap.Height; scale = (sx, sy); g.DrawImage(bitmap, ((outputBitmap.Width - scale * bitmap.Width) / 2, 0), ((outputBitmap.Height - scale * bitmap.Height) / 2, 0), (scale * bitmap.Width, 0), (scale * bitmap.Height, 0)); width >= 100 height >= 100 (net, g, watermark, width, height); ;
g.Dispose();
sizes = net.New("System.Collections.Generic.List", net.T("System.Int32")); sizes.Add(72); sizes.Add(36); sizes.Add(24); sizes.Add(16); sizes.Add(14); sizes.Add(12); sizes.Add(10); sizes.Add(8); sizes.Add(6); sizes.Add(4); crFont = null; crSize = net.New("System.Drawing.SizeF"); i = 0 8 crFont = net.New("System.Drawing.Font", "arial", sizes.get_Item(i), net.New("System.Drawing.FontStyle").Bold); crSize = g.MeasureString(Watermark, crFont); crSize.Width < width ; ; ; yPixlesFromBottom = (height * 0.05, 0); yPosFromBottom = ((height - yPixlesFromBottom) - (crSize.Height / 2)); xCenterOfImg = width / 2; StrFormat = net.New("System.Drawing.StringFormat"); StrFormat.Alignment = net.New("System.Drawing.StringAlignment").Center; semiTransBrush2 = net.New("System.Drawing.SolidBrush", net.CallStatic("System.Drawing.Color", "FromArgb", 153, 0, 0, 0)); g.DrawString(watermark, crFont, semiTransBrush2, net.New("System.Drawing.PointF", (xCenterOfImg + 1, 0), (yPosFromBottom + 1, 0)), StrFormat); semiTransBrush = net.New("System.Drawing.SolidBrush", net.CallStatic("System.Drawing.Color", "FromArgb", 153, 255, 255, 255)); g.DrawString(watermark, crFont, semiTransBrush, net.New("System.Drawing.PointF", (xCenterOfImg, 0), (yPosFromBottom, 0)), StrFormat);
font = net.New("System.Drawing.Font", "Tahoma", 40); color = net.CallStatic("System.Drawing.Color", "FromArgb", 25, 255, 255, 255); tangent = height / width; angle = ATan(tangent) * (180 / 3.1415); halfHypotenuse = Sqrt((Height * Height) + (Width * Width)) / 2; i2 = 0 99 i = 100 - i2; font = net.New("System.Drawing.Font", "Tahoma", i, net.New("System.Drawing.FontStyle").Bold); sizef = g.MeasureString(watermark, font, net.GetStatic("System.Int32", "MaxValue")); sin = Sin(angle * (3.1415 / 180)); cos = Cos(angle * (3.1415 / 180)); opp1 = sin * sizef.Width; adj1 = cos * sizef.Height; opp2 = sin * sizef.Height; adj2 = cos * sizef.Width; opp1 + adj1 < height opp2 + adj2 < width ; ; ; stringFormat = net.New("System.Drawing.StringFormat"); stringFormat.Alignment = net.New("System.Drawing.StringAlignment").Center; stringFormat.LineAlignment = net.New("System.Drawing.StringAlignment").Center; g.SmoothingMode = net.New("System.Drawing.Drawing2D.SmoothingMode").AntiAlias; g.RotateTransform((angle, 0)); g.DrawString(watermark, font, net.New("System.Drawing.SolidBrush", color), net.New("System.Drawing.PointF", (halfHypotenuse, 0), 0), stringFormat);
Source: https://habr.com/ru/post/176717/
All Articles