Exemplo n.º 1
0
        private byte[] PdfToImage(Enum_ArchiveItemMainType mainType, Enum_ArchiveItemFileType fileType, byte[] fileContent)
        {
            System.IO.MemoryStream myMemStream = new System.IO.MemoryStream(fileContent);
            var pdfFile = O2S.Components.PDFRender4NET.PDFFile.Open(myMemStream);
            var bitmap  = pdfFile.GetPageImage(0, 100);

            System.IO.MemoryStream myResult = new System.IO.MemoryStream();
            bitmap.Save(myResult, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(myResult.ToArray());
        }
Exemplo n.º 2
0
        private byte[] GetJpegThumbnail(Enum_ArchiveItemMainType mainType, Enum_ArchiveItemFileType fileType, byte[] fileContent)
        {
            if (mainType == Enum_ArchiveItemMainType.Image)
            {
                System.IO.MemoryStream myMemStream   = new System.IO.MemoryStream(fileContent);
                System.Drawing.Image   fullsizeImage = System.Drawing.Image.FromStream(myMemStream);

                float nPercent     = 0;
                float nPercentW    = 0;
                float nPercentH    = 0;
                var   sourceWidth  = fullsizeImage.Width;
                var   sourceHeight = fullsizeImage.Height;
                var   width        = 120;
                var   height       = 160;
                nPercentW = ((float)width / (float)sourceWidth);
                nPercentH = ((float)height / (float)sourceHeight);
                if (nPercentH < nPercentW)
                {
                    nPercent = nPercentH;
                }
                else
                {
                    nPercent = nPercentW;
                }

                int destWidth  = (int)(sourceWidth * nPercent);
                int destHeight = (int)(sourceHeight * nPercent);

                System.Drawing.Image   newImage = fullsizeImage.GetThumbnailImage(destWidth, destHeight, null, IntPtr.Zero);
                System.IO.MemoryStream myResult = new System.IO.MemoryStream();
                //System.Drawing.Imaging.ImageFormat format;
                //if (type == Enum_ArchiveItemType.JPG)
                //    format = System.Drawing.Imaging.ImageFormat.Jpeg;
                //همه jpg بشن
                newImage.Save(myResult, System.Drawing.Imaging.ImageFormat.Jpeg);  //Or whatever format you want.
                return(myResult.ToArray());
            }

            return(null);
        }
Exemplo n.º 3
0
 public Tuple <List <Enum_ArchiveItemFileType>, I_View_ViewArchiveItem> GetArhiveItemViewer(Enum_ArchiveItemMainType mainType, Enum_ArchiveItemFileType fileType)
 {
     if (mainType == Enum_ArchiveItemMainType.Image)
     {
         var fileTypes = new List <Enum_ArchiveItemFileType>()
         {
             Enum_ArchiveItemFileType.JPEG, Enum_ArchiveItemFileType.BMP, Enum_ArchiveItemFileType.GIF
         };
         return(new Tuple <List <Enum_ArchiveItemFileType>, I_View_ViewArchiveItem>(fileTypes, new frmViewImage()));
     }
     return(null);
 }
Exemplo n.º 4
0
        private bool SetPossibleThumbnail(MyIdeaDataDBEntities context, ArchiveItem dbArchiveItem, Enum_ArchiveItemMainType mainType, Enum_ArchiveItemFileType fileType, byte[] fileContent, string fileName)
        {
            byte[] thumbNail = null;
            if (mainType == Enum_ArchiveItemMainType.Image)
            {
                thumbNail = GetJpegThumbnail(mainType, fileType, fileContent);
            }
            else if (mainType == Enum_ArchiveItemMainType.Pdf)
            {
                var pdfToImage = PdfToImage(mainType, fileType, fileContent);
                if (pdfToImage != null)
                {
                    thumbNail = GetJpegThumbnail(Enum_ArchiveItemMainType.Image, Enum_ArchiveItemFileType.BMP, pdfToImage.ToArray());
                }
            }


            if (thumbNail != null)
            {
                FileRepositoryDTO attechedFile = new FileRepositoryDTO();
                attechedFile.Content = thumbNail;
                if (dbArchiveItem.ThumbnailFileRepositoryID != null)
                {
                    attechedFile.ID = dbArchiveItem.ThumbnailFileRepositoryID.Value;
                }
                attechedFile.FileName        = fileName;
                attechedFile.FileExtension   = "jpg";
                dbArchiveItem.FileRepository = bizFileRepository.ToFileRepository(context, attechedFile);
                return(true);
            }

            return(false);
        }