码迷,mamicode.com
首页 > 其他好文 > 详细

制作完赛证书

时间:2017-02-20 18:29:26      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:jpeg   poi   name   数值   一个人   pix   return   eric   oop   

制作完赛证书 项目 :scoreovr  GetHelper.cs

 private static void GenerateCert_30(ScoreReport scoreReport)
        {
            if (!scoreReport.MatchCompleted)
            {
                return;
            }
// 先测试生成一张证书  然后复制它的路径 按住shift 然后右键复制路径
            string templatePath = @"F:\SportsLoop\20170219惠州红花湖\惠州红花湖成绩证书定稿.png";

            Image certBitmap = Image.FromFile(templatePath);
            Graphics certGraphics = Graphics.FromImage(certBitmap);
            int fontSize = 88;
            if (scoreReport.Bib == "A038")
            {
                fontSize = 60;
            }
//定义字体 文字大小 风格   GraphicsUnit.Pixel的时候可以用像素 定义它的大小 .point的时候用长宽就可以
            Font font = new Font("黑体", fontSize, FontStyle.Regular, GraphicsUnit.Pixel);
            StringFormat stringFormat = new StringFormat(StringFormat.GenericTypographic);
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Far;
            stringFormat.FormatFlags |= StringFormatFlags.NoWrap;
//这行用取色器取出文字的颜色 233是固定值 后面三个数填上取色器取出的数值 Brush fontBrush
= new SolidBrush(Color.FromArgb(233, 0, 0, 0)); // 这行是定义添加选手的名字大小 和位置 前两个数字是矩形框左上角的坐标的X,Y 值 后两个数字是矩形框的长宽 // Draw name RectangleF nameRect = new RectangleF(698, 949, 605, 117); certGraphics.DrawString(scoreReport.PlayerName, font, fontBrush, nameRect, stringFormat); // Draw event name RectangleF eventRect = new RectangleF(698, 1219, 605, 117); certGraphics.DrawString(scoreReport.EventName.ToString(), font, fontBrush, eventRect, stringFormat); // Draw bib RectangleF bibRect = new RectangleF(698, 1478, 605, 117); certGraphics.DrawString(scoreReport.Bib, font, fontBrush, bibRect, stringFormat); // Draw Score string displayScore = scoreReport.NetTime.Value.ToString(@"hh\:mm\:ss"); RectangleF scoreRect = new RectangleF(698, 1741, 605, 117); certGraphics.DrawString(displayScore, font, fontBrush, scoreRect, stringFormat); Image png = certBitmap.GetThumbnailImage(certBitmap.Width, certBitmap.Height, () => { return false; }, IntPtr.Zero);
//这个是生成证书的路径 一般建立一个叫cert的文件夹 png.Save(
string.Format(@"F:\SportsLoop\20170219惠州红花湖\certs\cert_{0}.jpg", scoreReport.Bib), ImageFormat.Jpeg);
下面这几行调试的时候一搬注释掉 最后确定效果了再取消注释运行一下 scoreReport.CertPath
= $"http://www.sportsloop.com.cn/score/certs/{scoreReport.MatchID}/cert_{scoreReport.Bib}.jpg";
//制作完赛证书的时候不按照这个规则对成绩进行排序 scoreReport.Rank
= null; scoreReport.Locked = true; ScoreLogic.SaveScoreReport(scoreReport); }

调试的时候可以在前面加一个断点,然后后面的代码就可以进行修改,先在ovr里点开一个人制作完赛证书 最后在所有人里面制作一下完赛证书

制作完赛证书

标签:jpeg   poi   name   数值   一个人   pix   return   eric   oop   

原文地址:http://www.cnblogs.com/mrqinxw/p/6420557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!