コード例 #1
0
        void SaveImage(string glyph, IFormFile file)
        {
            string ssDirPath = Path.Combine("wwwroot", "Screenshots", glyph);

            if (Directory.Exists(ssDirPath) == false)
            {
                Directory.CreateDirectory(ssDirPath);
            }

            string Id        = System.Guid.NewGuid().ToString("N");
            string filePath  = Path.Combine(ssDirPath, $"{Id}.png");
            string thumbPath = Path.Combine(ssDirPath, $"{Id}-thumb.png");

            using (var img = Image.Load <Rgba32>(file.OpenReadStream()))
            {
                // Main Image
                using (var output = FileIo.OpenWrite(filePath))
                {
                    if (img.Width > 1920 || img.Height > 1080)
                    {
                        img.Mutate(i => i.Resize(1920, 1080));
                    }

                    img.SaveAsPng(output);
                }

                // Thumbnail
                using (var output = FileIo.OpenWrite(thumbPath))
                {
                    img.Mutate(i => i.Resize(256, 128));
                    img.SaveAsPng(output);
                }
            }
        }