示例#1
0
        public async Task StopStreamAsync(IUserMessage msg, ImageSharp.Image <Rgba32> image) /*Creates an async task with UserMessage as a paramater */
        {
            string input = "abcdefghijklmnopqrstuvwxyz0123456789";                           /*alphabet abcdefghijklmaopqrstuvwxy and z! now I know my abc's!*/
            char   ch;
            string temp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Temp");
            Random rand = new Random();

            for (int i = 0; i < 8; i++)/*loops through the alphabet and creates a random string with 8 random characters */
            {
                ch            = input[rand.Next(0, input.Length)];
                randomString += ch;
            }
            if (image != null) /*Checks if the image we created is not null if it is then this part won't run*/
            {
                Stream outputStream = new MemoryStream();
                image.SaveAsPng(outputStream);                         /*saves the image as a jpg you can of course change this*/
                outputStream.Position = 0;
                var file = File.Create(temp + $"/{randomString}.png"); /*creates a file with the random string as the name*/
                await outputStream.CopyToAsync(file);

                file.Dispose();
                await msg.Channel.SendFileAsync(temp + $"/{randomString}.png"); /*sends the image we just created*/

                File.Delete($"temp+/{randomString}.png");                       /*deletes the image after sending*/
            }
        }
示例#2
0
        public static Stream ToStream(this ImageSharp.Image <Rgba32> img)
        {
            var imageStream = new MemoryStream();

            img.SaveAsPng(imageStream);
            imageStream.Position = 0;
            return(imageStream);
        }
        public static MemoryStream ToStream(this ImageSharp.Image <Rgba32> img)
        {
            var imageStream = new MemoryStream();

            img.SaveAsPng(imageStream, new ImageSharp.Formats.PngEncoder()
            {
                CompressionLevel = 9
            });
            imageStream.Position = 0;
            return(imageStream);
        }