Пример #1
0
        public static void GenerateImageFile(ImageFormat imageFormat, AttachmentModel attachment, int companyID, int id)
        {
            bool pathExists = Directory.Exists(Path);

            if (!pathExists)
            {
                throw new Exception("Please check your project path and custmise the path in the script.");
            }
            string attachmentPath       = $@"{Path}/Attachment";
            bool   attachmentPathExists = Directory.Exists(attachmentPath);

            if (!attachmentPathExists)
            {
                Directory.CreateDirectory(attachmentPath);
            }
            string smallPath       = $@"{Path}/Attachment/{companyID}/Small";
            bool   smallPathExists = Directory.Exists(smallPath);

            if (!smallPathExists)
            {
                Directory.CreateDirectory(smallPath);
            }
            string largePath       = $@"{Path}/Attachment/{companyID}/Large";
            bool   largePathExists = Directory.Exists(largePath);

            if (!largePathExists)
            {
                Directory.CreateDirectory(largePath);
            }
            string rawPath       = $@"{Path}/Attachment/{companyID}/Raw";
            bool   rawPathExists = Directory.Exists(rawPath);

            if (!rawPathExists)
            {
                Directory.CreateDirectory(rawPath);
            }
            string pdfPath       = $@"{Path}/Attachment/{companyID}/Pdf";
            bool   pdfPathExists = Directory.Exists(pdfPath);

            if (!pdfPathExists)
            {
                Directory.CreateDirectory(pdfPath);
            }

            var smallImage = ConvertBinaryFile(attachment, false, SmallWidth, Smallheight);

            smallImage.Save($@"{Path}/Attachment/{companyID}/Small/{id}_200x130.{imageFormat}", imageFormat);

            var largeImage = ConvertBinaryFile(attachment, false, LargeWidth, Largeheight);

            largeImage.Save($@"{Path}/Attachment/{companyID}/Large/{id}_1024x666.{imageFormat}", imageFormat);

            var rawImage = ConvertBinaryFile(attachment, true, null, null);

            rawImage.Save($@"{Path}/Attachment/{companyID}/Raw/{id}_raw.{imageFormat}", imageFormat);
        }
Пример #2
0
 public static Image ConvertBinaryFile(AttachmentModel attachment, bool raw, int?width, int?height)
 {
     if (!raw)
     {
         var img = ByteArrayToImage(attachment.ContentAsBytes);
         if (width.HasValue && height.HasValue && width.Value > 0 && height.Value > 0)
         {
             img = ResizeImage(img, width.Value, height.Value);
         }
         return(img);
     }
     else
     {
         var img = ByteArrayToImage(attachment.ContentAsBytes);
         img = ResizeImage(img, img.Width, img.Height);
         return(img);
     }
 }