using Org.BouncyCastle.Asn1.Cms; using PoEco.Net.JSON; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.IO.Ports; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using static System.Net.Mime.MediaTypeNames; using Image = System.Drawing.Image; namespace PoEco.Net.Utilities { internal class Draw { public static void GenQuad(int w, int h, int x, int y, string imgUrl, double min, double max, string type, string user, string discriminator) { int fontsize = 16; int calculatedW = w * 47; int calculatedH = h * 47; int calculatedX = x * 47; int calculatedY = y * 47; Color cborder = Color.FromArgb(61,235,52); // Adjust font size by item size // w == item width // h == item height switch (w) { case 1: switch (h) { case 1: fontsize = 12; break; case 3: fontsize = 12; break; } break; } ColorConverter cc = new ColorConverter(); Color fontc = (Color)cc.ConvertFromString("#3d3d3b"); switch (type) { case "c": if (min < 10) { fontc = (Color)cc.ConvertFromString("#fc0303"); } if (min >= 10 && min < 20) { fontc = (Color)cc.ConvertFromString("#fc5e03"); } if (min >= 20 && min < 50) { fontc = (Color)cc.ConvertFromString("#fcce03"); } if (min >= 50) { fontc = (Color)cc.ConvertFromString("#29f705"); } break; case "d": fontc = (Color)cc.ConvertFromString("#29f705"); break; } var fontFamily = new FontFamily("Verdana"); var vfont = new Font(fontFamily, fontsize, FontStyle.Regular, GraphicsUnit.Pixel); Image imageFile = Image.FromFile($@"data/tabmap/{user}#{discriminator}.png"); Graphics newGraphics = Graphics.FromImage(imageFile); Pen border = new Pen(cborder, 2); Pen backPen = new Pen(cborder, 0); SolidBrush back = new SolidBrush((Color)cc.ConvertFromString("#3d3d3b")); SolidBrush font = new SolidBrush(fontc); Rectangle rect = new Rectangle(calculatedX, calculatedY, calculatedW, calculatedH); Rectangle backgroundRect = new Rectangle(calculatedX, calculatedY, calculatedW-5, calculatedH-5); newGraphics.DrawRectangle(border, rect); newGraphics.FillRectangle(back, rect); newGraphics.DrawRectangle(border, rect); WebClient wc = new WebClient(); byte[] bytes = wc.DownloadData(imgUrl); MemoryStream ms = new MemoryStream(bytes); Image itemIcon = Image.FromStream(ms); Bitmap bmp = new Bitmap(itemIcon.Width, itemIcon.Height); ColorMatrix matrix = new ColorMatrix(); matrix.Matrix33 = 0.3f; ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); newGraphics.DrawImage(itemIcon, new Rectangle(x * 47, y * 47, bmp.Width, bmp.Height), 0 , 0, itemIcon.Width, itemIcon.Height, GraphicsUnit.Pixel, attributes); StringFormat stringFormatMin = new StringFormat(); stringFormatMin.Alignment = StringAlignment.Center; stringFormatMin.LineAlignment = StringAlignment.Near; newGraphics.DrawString(min.ToString() + type, vfont, font, rect, stringFormatMin); StringFormat stringFormatMax = new StringFormat(); stringFormatMax.Alignment = StringAlignment.Center; stringFormatMax.LineAlignment = StringAlignment.Far; newGraphics.DrawString(max.ToString() + type, vfont, font, rect, stringFormatMax); imageFile.Save($@"data/tabmap/{user}#{discriminator}.png", ImageFormat.Bmp); if (Settings.GetWeb()) { File.Copy($@"data/tabmap/{user}#{discriminator}.png", $@"{Settings.GetWebPath()}/{user}#{discriminator}.png", true); } } } }