Guest User

DrawLevelCard

a guest
Sep 2nd, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. public static Bitmap DrawLevelCard(string AvatarURL, ulong MemberID, string DisplayName, string Discriminator, int Level, double ExpNeeded, double CurrentExp, UserStatus Status, Color CustomColor, string BackgroundURL = null)
  2. {
  3.     Font Levelfont = GetFontName(16);
  4.  
  5.     Bitmap img = new Bitmap(935, 285);
  6.     if(BackgroundURL == null || BackgroundURL == "") {
  7.         for (var x = 0; x < img.Width; x++)
  8.         {
  9.             for (var y = 0; y < img.Height; y++)
  10.             {
  11.                 img.SetPixel(x, y, Color.FromArgb(255, 44, 47, 51));
  12.             }
  13.         }
  14.     }
  15.     else
  16.     {
  17.         using (Graphics gr1 = Graphics.FromImage(img))
  18.         {
  19.             gr1.SmoothingMode = SmoothingMode.AntiAlias;
  20.             gr1.InterpolationMode = InterpolationMode.High;
  21.             gr1.DrawImage(GetBackgroundImage(BackgroundURL, ImageFormat.Png), new Point(0, 0));
  22.         }
  23.     }
  24.     using (Graphics gr = Graphics.FromImage(img))
  25.     {
  26.         gr.SmoothingMode = SmoothingMode.AntiAlias;
  27.         gr.InterpolationMode = InterpolationMode.High;
  28.  
  29.         GraphicsPath BackgroundCard = RoundedRect(new Rectangle(25, 35, 885, 215),10);
  30.         GraphicsPath BackExpBar = RoundedRect(new Rectangle(261, 183, 632, 42),20);
  31.         GraphicsPath FrontExpBar = RoundedRect(new Rectangle(262, 184, 630, 40),20);
  32.         double ExpRatio = (CurrentExp / ExpNeeded);
  33.         double widthOfExpBar = (630 * ExpRatio);
  34.         Rectangle ExpBarRec = new Rectangle(262, 184, (int)widthOfExpBar, 40);
  35.         GraphicsPath ExpBar = RoundedRect(ExpBarRec, 20);
  36.         RectangleF rectName = new RectangleF(262, 130, 298, 55);
  37.         RectangleF rectDiscriminator = new RectangleF(550, 130, 110, 54);
  38.         if(BackgroundURL != null || BackgroundURL == "")
  39.         {
  40.             gr.FillPath(new SolidBrush(Color.FromArgb(185, 35, 39, 42)), BackgroundCard);
  41.         }
  42.         else
  43.         {
  44.             gr.FillPath(new SolidBrush(Color.FromArgb(100, 35, 39, 42)), BackgroundCard);
  45.         }
  46.         gr.FillPath(new SolidBrush(Color.FromArgb(255, 20, 20, 20)), BackExpBar);
  47.         gr.FillPath(new SolidBrush(Color.FromArgb(255, 72, 75, 78)), FrontExpBar);
  48.         if(CurrentExp != 0)
  49.         {
  50.             gr.FillPath(new SolidBrush(CustomColor), ExpBar);
  51.         }
  52.         gr.DrawImage(GetAvatarImage(AvatarURL, ImageFormat.Png), new Point(39, 57));
  53.         //gr.FillEllipse(Brushes.Red, 39, 57, 173, 173);
  54.         gr.FillEllipse(Brushes.Black, 164, 172, 51, 51);
  55.         var getStatus = new Dictionary<string, Brush>(){
  56.             { "Online", new SolidBrush(Color.FromArgb(255, 67, 181, 129))},
  57.             { "Idle", new SolidBrush(Color.FromArgb(255, 250, 166, 26))},
  58.             { "DoNotDisturb", new SolidBrush(Color.FromArgb(255, 240, 71, 71))},
  59.             { "Offline", new SolidBrush(Color.FromArgb(255, 133, 144, 147))}
  60.         };
  61.         gr.FillEllipse(getStatus[Status.ToString()], 165, 173, 49, 49);
  62.  
  63.         var measure = gr.MeasureString(DisplayName, GetFontName(36));
  64.         int width = (int)measure.Width;
  65.         int Beginheight = (int)measure.Height;
  66.         int height = Beginheight;
  67.         var measure2 = gr.MeasureString(Discriminator, GetFontName(24));
  68.         int width2 = (int)measure2.Width;
  69.         int Beginheight2 = (int)measure2.Height;
  70.         int height2 = Beginheight2;
  71.         var measure3 = gr.MeasureString(" / " + ExpNeeded + " Exp", Levelfont);
  72.         int width3 = (int)measure3.Width;
  73.         var measure4 = gr.MeasureString(CurrentExp.ToString(), Levelfont);
  74.         int width4 = (int)measure4.Width;
  75.         int i = 0;
  76.         while (width + width2 >= 440)
  77.         {
  78.             i++;
  79.             measure = gr.MeasureString(DisplayName, GetFontName(36-i));
  80.             width = (int)measure.Width;
  81.             height = (int)measure.Height;
  82.             measure2 = gr.MeasureString(Discriminator, GetFontName(24-i));
  83.             width2 = (int)measure2.Width;
  84.             height2 = (int)measure2.Height;
  85.         }
  86.         gr.DrawString(DisplayName, GetFontName(36 - i), Brushes.White, 265, 125 + (Beginheight - height));
  87.         gr.DrawString(Discriminator, GetFontName(24 - i), Brushes.Gray, 250 + (width), 141 + (Beginheight2 - height2));
  88.         gr.DrawString(" / " + ExpNeeded + " Exp", Levelfont, new SolidBrush(Color.FromArgb(255, 72, 75, 78)), 262 + 630 - width3, 154);
  89.         gr.DrawString(CurrentExp.ToString(), Levelfont, new SolidBrush(CustomColor), 262 + 630 - width3-width4, 154);
  90.     }
  91.  
  92.     img.Save("C:\\Users\\gunzb\\Desktop\\log\\LevelCard_" + MemberID + ".png");
  93.     img.Dispose();
  94.  
  95.     return img;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment