示例#1
0
        public async Task <IActionResult> Generate_terapia_V1_0(Guid id, long uniDate)
        {
            var certifications = await _certificatesBaseRepository.GetAllAsync();

            var    certification = certifications.SingleOrDefault(x => x.Id == Guid.Parse(id.ToString()));
            Bitmap bitmapClear;
            // foreach (var certification in certifications)
            // {
            var image = Image.FromFile("Files/template-hypnos.png");

            var cert = new Bitmap(image);


            bitmapClear = new Bitmap(cert.Width, cert.Height);
            using (Graphics graphics = Graphics.FromImage(bitmapClear))
            {
                graphics.DrawImage(cert, 0, 0, cert.Width, cert.Height);

                var fio = certification.Lastname + " " + certification.Firstname +
                          " " + (string.IsNullOrEmpty(certification.Middlename)
                                  ? " "
                                  : " " + certification.Middlename); //certification.FIO.Replace(" ", "\r\n");
                ImageHelper.AddedText(fio, cert, graphics, "Arial", 95, Brushes.Black, 1265, StringAlignment.Center,
                                      StringAlignment.Center);

                var date = uniDate.ConvertToDateTime();
                ImageHelper.AddedTextX(date.ToString("dd.MM.yyyy"), cert, graphics, "Arial", 68, Brushes.Black,
                                       2090,
                                       2539, StringAlignment.Center, StringAlignment.Center);
                ////added serial_number
                //ImageHelper.AddedText(certification.SerialNumber, cert, graphics, "Arial", 45, Brushes.Red, 2727, StringAlignment.Center, StringAlignment.Near);

                //graphics.DrawImage(qrCodeImage, 1070, 2901, qrCodeImage.Width, qrCodeImage.Height);
                graphics.Save();
                // bitmapClear.Save(fio + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            // }

            var bitmapBytes = ImageHelper.BitmapToBytes(bitmapClear);  //Convert bitmap into a byte array

            return(File(bitmapBytes, "image/jpeg"));
            // return Ok();
        }