Esempio n. 1
0
        private Stream DrawFrame(TextFactory graphics, string content, Color color, ImageProperties properties = null)
        {
            var stream = new MemoryStream();

            using Bitmap frame = graphics.DrawText(content, color, properties);
            frame.Save(stream, ImageFormat.Png);
            return(stream);
        }
Esempio n. 2
0
        public async Task DrawMonoTextAsync([Remainder] string text)
        {
            string   path = $"../tmp/{Context.User.Id}_text.png";
            FontFace font = JsonHandler.Load <FontFace>(@"../assets/fonts/monori.json");

            // new OutlineProperties(1, new OriColor(0x44B29B)): Too taxing on performance as of now
            char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());
            var          config  = TextFactoryConfig.Default;

            config.CharMap = charMap;
            var properties = new ImageProperties {
                TrimEmptyPixels = true, Padding = new Padding(2), Matte = new ImmutableColor(0x0C525F)
            };

            using (var factory = new TextFactory(config))
                using (Bitmap bmp = factory.DrawText(text, font, ImmutableColor.GammaGreen, properties))
                    ImageHelper.Save(bmp, path, ImageFormat.Png);

            await Context.Channel.SendFileAsync(path);
        }
Esempio n. 3
0
        private List <Stream> GetTextFrames(params string[] texts)
        {
            if (texts.Length == 0)
            {
                throw new ArgumentNullException("At least one text must be written.");
            }

            var frames = new List <Stream>();

            FontFace font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json");

            char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());

            var config = TextFactoryConfig.Default;

            config.CharMap = charMap;

            using (var factory = new TextFactory(config))
            {
                var properties = new ImageProperties
                {
                    TrimEmptyPixels = false,
                    Padding         = new Padding(2),
                    Matte           = new ImmutableColor(0x0C525F)
                };

                for (int i = 0; i < texts.Length; i++)
                {
                    var stream = new MemoryStream();

                    using (Bitmap frame = factory.DrawText(texts[i], font, ImmutableColor.GammaGreen, properties))
                        frame.Save(stream, ImageFormat.Png);

                    frames.Add(stream);
                }
            }

            return(frames);
        }
Esempio n. 4
0
        public async Task GetTimeAsync(float hour)
        {
            if (hour > 23.00f || hour < 0.00f)
            {
                await Context.Channel.SendMessageAsync("hour out of range");

                return;
            }

            try
            {
                string path = $"../tmp/{Context.User.Id}_time.png";
                var    font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json");
                // new OutlineProperties(1, new OriColor(0x44B29B)): Too taxing on performance as of now
                char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());
                GammaPalette colors  = TimeCycle.FromHour(hour);
                var          config  = TextFactoryConfig.Default;
                config.CharMap = charMap;
                var properties = new ImageProperties
                {
                    TrimEmptyPixels = true,
                    Padding         = new Padding(2),
                    Matte           = colors[Gamma.Min]
                };

                using (var factory = new TextFactory(config))
                    using (Bitmap bmp = factory.DrawText(hour.ToString("00.00H").ToUpper(), font, properties))
                        ImageHelper.Save(bmp, path, ImageFormat.Png);

                await Context.Channel.SendFileAsync(path);
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }