Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DSharpPlus.Entities;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Runtime.InteropServices.ComTypes;
- using System.Text;
- namespace GBot.CardHandler
- {
- public class CardHandle
- {
- 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)
- {
- Bitmap img = new Bitmap(935, 285);
- if(BackgroundURL == null || BackgroundURL == "") {
- for (var x = 0; x < img.Width; x++)
- {
- for (var y = 0; y < img.Height; y++)
- {
- img.SetPixel(x, y, Color.FromArgb(255, 44, 47, 51));
- }
- }
- }
- else
- {
- using (Graphics gr1 = Graphics.FromImage(img))
- {
- gr1.SmoothingMode = SmoothingMode.AntiAlias;
- gr1.InterpolationMode = InterpolationMode.High;
- gr1.DrawImage(GetBackgroundImage(BackgroundURL, ImageFormat.Png), new Point(0, 0));
- }
- }
- using (Graphics gr = Graphics.FromImage(img))
- {
- gr.SmoothingMode = SmoothingMode.AntiAlias;
- gr.InterpolationMode = InterpolationMode.High;
- GraphicsPath BackgroundCard = RoundedRect(new Rectangle(25, 35, 885, 215),10);
- GraphicsPath BackExpBar = RoundedRect(new Rectangle(261, 183, 632, 42),20);
- GraphicsPath FrontExpBar = RoundedRect(new Rectangle(262, 184, 630, 40),20);
- double ExpRatio = (CurrentExp / ExpNeeded);
- double widthOfExpBar = (630 * ExpRatio);
- Rectangle ExpBarRec = new Rectangle(262, 184, (int)widthOfExpBar, 40);
- GraphicsPath ExpBar = RoundedRect(ExpBarRec, 20);
- RectangleF rectName = new RectangleF(262, 130, 298, 55);
- RectangleF rectDiscriminator = new RectangleF(550, 130, 110, 54);
- if(BackgroundURL != null || BackgroundURL == "")
- {
- gr.FillPath(new SolidBrush(Color.FromArgb(185, 35, 39, 42)), BackgroundCard);
- }
- else
- {
- gr.FillPath(new SolidBrush(Color.FromArgb(100, 35, 39, 42)), BackgroundCard);
- }
- gr.FillPath(new SolidBrush(Color.FromArgb(255, 20, 20, 20)), BackExpBar);
- gr.FillPath(new SolidBrush(Color.FromArgb(255, 72, 75, 78)), FrontExpBar);
- if(CurrentExp != 0)
- {
- gr.FillPath(new SolidBrush(CustomColor), ExpBar);
- }
- gr.DrawImage(GetAvatarImage(AvatarURL, ImageFormat.Png), new Point(39, 57));
- //gr.FillEllipse(Brushes.Red, 39, 57, 173, 173);
- gr.FillEllipse(Brushes.Black, 164, 172, 51, 51);
- var getStatus = new Dictionary<string, Brush>(){
- { "Online", new SolidBrush(Color.FromArgb(255, 67, 181, 129))},
- { "Idle", new SolidBrush(Color.FromArgb(255, 250, 166, 26))},
- { "DoNotDisturb", new SolidBrush(Color.FromArgb(255, 240, 71, 71))},
- { "Offline", new SolidBrush(Color.FromArgb(255, 133, 144, 147))}
- };
- gr.FillEllipse(getStatus[Status.ToString()], 165, 173, 49, 49);
- var measure = gr.MeasureString(DisplayName, GetFontName(36));
- int width = (int)measure.Width;
- int Beginheight = (int)measure.Height;
- int height = Beginheight;
- var measure2 = gr.MeasureString(Discriminator, GetFontName(24));
- int width2 = (int)measure2.Width;
- int Beginheight2 = (int)measure2.Height;
- int height2 = Beginheight2;
- var measure3 = gr.MeasureString(" / " + ExpNeeded + " Exp", GetFontName(16));
- int width3 = (int)measure3.Width;
- var measure4 = gr.MeasureString(CurrentExp.ToString(), GetFontName(16));
- int width4 = (int)measure4.Width;
- int i = 0;
- while (width + width2 >= 440)
- {
- i++;
- measure = gr.MeasureString(DisplayName, GetFontName(36-i));
- width = (int)measure.Width;
- height = (int)measure.Height;
- measure2 = gr.MeasureString(Discriminator, GetFontName(24-i));
- width2 = (int)measure2.Width;
- height2 = (int)measure2.Height;
- }
- gr.DrawString(DisplayName, GetFontName(36 - i), Brushes.White, 265, 125 + (Beginheight - height));
- gr.DrawString(Discriminator, GetFontName(24 - i), Brushes.Gray, 250 + (width), 141 + (Beginheight2 - height2));
- gr.DrawString(" / " + ExpNeeded + " Exp", GetFontName(16), new SolidBrush(Color.FromArgb(255, 72, 75, 78)), 262 + 630 - width3, 154);
- gr.DrawString(CurrentExp.ToString(), GetFontName(16), new SolidBrush(CustomColor), 262 + 630 - width3-width4, 154);
- }
- img.Save(".\\Assets\\LevelCard_" + MemberID + ".png");
- img.Dispose();
- return img;
- }
- public static Bitmap DrawPointCard(string AvatarURL, ulong MemberID, string DisplayName, string Discriminator, int Points, DateTime DailyTime, int DailyCount, UserStatus Status, Color CustomColor, string BackgroundURL = null)
- {
- Font Namefont = GetFontName(36);
- Font Discriminatorfont = GetFontName(24);
- Bitmap img = new Bitmap(935, 285);
- if (BackgroundURL == null || BackgroundURL == "")
- {
- for (var x = 0; x < img.Width; x++)
- {
- for (var y = 0; y < img.Height; y++)
- {
- img.SetPixel(x, y, Color.FromArgb(255, 44, 47, 51));
- }
- }
- }
- else
- {
- using (Graphics gr1 = Graphics.FromImage(img))
- {
- gr1.SmoothingMode = SmoothingMode.AntiAlias;
- gr1.InterpolationMode = InterpolationMode.High;
- gr1.DrawImage(GetBackgroundImage(BackgroundURL, ImageFormat.Png), new Point(0, 0));
- }
- }
- using (Graphics gr = Graphics.FromImage(img))
- {
- gr.SmoothingMode = SmoothingMode.AntiAlias;
- gr.InterpolationMode = InterpolationMode.High;
- var measure = gr.MeasureString(DisplayName, GetFontName(36));
- int width = (int)measure.Width;
- int Beginheight = (int)measure.Height;
- int height = Beginheight;
- var measure2 = gr.MeasureString(Discriminator, GetFontName(24));
- int width2 = (int)measure2.Width;
- int Beginheight2 = (int)measure2.Height;
- int height2 = Beginheight2;
- int i = 0;
- while (width + width2 >= 630)
- {
- i++;
- measure = gr.MeasureString(DisplayName, GetFontName(36 - i));
- width = (int)measure.Width;
- height = (int)measure.Height;
- measure2 = gr.MeasureString(Discriminator, GetFontName(24 - i));
- width2 = (int)measure2.Width;
- height2 = (int)measure2.Height;
- }
- GraphicsPath BackgroundCard = RoundedRect(new Rectangle(25, 35, 885, 215),10);
- GraphicsPath BackUnderlineBar = RoundedRect(new Rectangle(261, 98, (width + width2) + 2, 12),5);
- GraphicsPath FrontUnderlineBar = RoundedRect(new Rectangle(262, 99, (width + width2), 10),5);
- RectangleF rectName = new RectangleF(262, 130, 298, 55);
- RectangleF rectDiscriminator = new RectangleF(550, 130, 110, 54);
- if (BackgroundURL != null || BackgroundURL == "")
- {
- gr.FillPath(new SolidBrush(Color.FromArgb(185, 35, 39, 42)), BackgroundCard);
- }
- else
- {
- gr.FillPath(new SolidBrush(Color.FromArgb(100, 35, 39, 42)), BackgroundCard);
- }
- gr.FillPath(new SolidBrush(Color.FromArgb(255, 20, 20, 20)), BackUnderlineBar);
- gr.FillPath(new SolidBrush((Color)CustomColor), FrontUnderlineBar);
- gr.DrawImage(GetAvatarImage(AvatarURL, ImageFormat.Png), new Point(39, 57));
- //gr.FillEllipse(Brushes.Red, 39, 57, 173, 173);
- gr.FillEllipse(Brushes.Black, 164, 172, 51, 51);
- var getStatus = new Dictionary<string, Brush>(){
- { "Online", new SolidBrush(Color.FromArgb(255, 67, 181, 129))},
- { "Idle", new SolidBrush(Color.FromArgb(255, 250, 166, 26))},
- { "DoNotDisturb", new SolidBrush(Color.FromArgb(255, 240, 71, 71))},
- { "Offline", new SolidBrush(Color.FromArgb(255, 133, 144, 147))}
- };
- gr.FillEllipse(getStatus[Status.ToString()], 165, 173, 49, 49);
- gr.DrawString(DisplayName, GetFontName(36 - i), Brushes.White, 265, 40 + (Beginheight - height));
- gr.DrawString(Discriminator, GetFontName(24 - i), Brushes.Gray, 250 + (width), 56 + (Beginheight2 - height2));
- }
- img.Save(".\\Assets\\PointCard_" + MemberID + ".png");
- img.Dispose();
- return img;
- }
- private static Font GetFontName(float msSize)
- {
- PrivateFontCollection collection = new PrivateFontCollection();
- collection.AddFontFile(@".\Fonts\Tommy Soft Regular.otf");
- FontFamily fontFamily = new FontFamily("MADE Tommy Soft", collection);
- collection.Dispose();
- return new Font(fontFamily, msSize);
- }
- public static Bitmap GetAvatarImage(string imageUrl, ImageFormat format)
- {
- WebClient client = new WebClient();
- Stream stream = client.OpenRead(imageUrl);
- Bitmap bitmap;
- bitmap = new Bitmap(stream);
- stream.Flush();
- stream.Close();
- stream.Dispose();
- client.Dispose();
- return ResizeImage(bitmap, 173, 173);
- }
- public static Bitmap GetBackgroundImage(string imageUrl, ImageFormat format)
- {
- WebClient client = new WebClient();
- Stream stream = client.OpenRead(imageUrl);
- Bitmap bitmap;
- bitmap = new Bitmap(stream);
- stream.Flush();
- stream.Close();
- client.Dispose();
- return ResizeImage(bitmap, 935, 285);
- }
- public static Bitmap ResizeImage(Image image, int width, int height)
- {
- var destRect = new Rectangle(0, 0, width, height);
- var destImage = new Bitmap(width, height);
- destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
- using (var graphics = Graphics.FromImage(destImage))
- {
- graphics.CompositingMode = CompositingMode.SourceCopy;
- graphics.CompositingQuality = CompositingQuality.HighQuality;
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.SmoothingMode = SmoothingMode.HighQuality;
- graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- using (var wrapMode = new ImageAttributes())
- {
- wrapMode.SetWrapMode(WrapMode.TileFlipXY);
- graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
- }
- }
- return destImage;
- }
- public static Bitmap ClipToCircle(Bitmap original, PointF center, float radius)
- {
- Bitmap copy = new Bitmap(original);
- using (Graphics g = Graphics.FromImage(copy))
- {
- RectangleF r = new RectangleF(center.X - radius, center.Y - radius, radius * 2, radius * 2);
- GraphicsPath path = new GraphicsPath();
- path.AddEllipse(r);
- g.Clip = new Region(path);
- g.DrawImage(original, 0, 0);
- return copy;
- }
- }
- public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
- {
- int diameter = radius * 2;
- Size size = new Size(diameter, diameter);
- Rectangle arc = new Rectangle(bounds.Location, size);
- GraphicsPath path = new GraphicsPath();
- if(bounds.Height >= bounds.Width)
- {
- bounds.Width = bounds.Height;
- }
- if (radius >= diameter) {
- path.AddRectangle(bounds);
- return path;
- }
- // top left arc
- path.AddArc(arc, 180, 90);
- // top right arc
- arc.X = bounds.Right - diameter;
- path.AddArc(arc, 270, 90);
- // bottom right arc
- arc.Y = bounds.Bottom - diameter;
- path.AddArc(arc, 0, 90);
- // bottom left arc
- arc.X = bounds.Left;
- path.AddArc(arc, 90, 90);
- path.CloseFigure();
- return path;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment