public static void GenerateCard(string outputPath)
        {
            var character1 = new CharacterCard();

            CharacterValueMap.UpdateCardFromJson(character1, SampleData.Character1);
            var width  = 300;
            var height = 419;

            using (var image = new Bitmap(width, height))
            {
                using (var graphics = Graphics.FromImage(image))
                {
                    graphics.TextContrast      = 0;
                    graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                    GenerateCharacterCardGraphics(graphics, character1);
                    image.Save(outputPath, ImageFormat.Png);
                }
            }
        }
示例#2
0
        public static void GenerateCard(string outputPath)
        {
            var character1 = new CharacterCard();
            CharacterValueMap.UpdateCardFromJson(character1, SampleData.Character1);
            var width = 300;
            var height = 419;

            var document = new PdfDocument();
            var page = document.AddPage();
            page.Width = width;
            page.Height = height;
            
            var graphics = XGraphics.FromPdfPage(page);

            GenerateCharacterCardGraphics(graphics, character1);

            var fileInfo = new FileInfo(outputPath);
            document.Save(fileInfo.FullName);
        }
示例#3
0
        public static void GenerateCard(string outputPath)
        {
            var character1 = new CharacterCard();

            CharacterValueMap.UpdateCardFromJson(character1, SampleData.Character1);

            var sb = new StringBuilder();

            sb.Append("<html><head>");
            sb.Append($"<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\" /><meta charset=\"utf-8\" />");
            sb.Append($"<style>{File.ReadAllText("styles.css")}</style></head>");
            sb.Append("<body>");
            GenerateCharacterCardGraphics(sb, character1);
            sb.Append("</body></html>");

            var fileInfo = new FileInfo(outputPath);

            using (FileStream fs = new FileStream(fileInfo.FullName, FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    w.Write(sb.ToString());
                }
            }
            var converter = new HtmlConverter();
            var bytes     = converter.FromHtmlString(sb.ToString(), 300);

            using (Image <Rgba32> image = Image.Load(bytes))
            {
                var ratio  = (double)image.Height / image.Width;
                var width  = 300;
                var height = (int)(ratio * 300);
                image.Mutate(x => x.Resize(width, height));
                image.Save("test.jpg");
            }
        }