Exemple #1
0
        public static byte[] CreateThumbVideo(byte[] byteArray)
        {
            try
            {
                System.Drawing.Image imThumbnailImage;
                System.Drawing.Image OriginalImage;
                MemoryStream         ms = new MemoryStream();

                // Stream / Write Image to Memory Stream from the Byte Array.
                ms.Write(byteArray, 0, byteArray.Length);

                OriginalImage = System.Drawing.Image.FromStream(ms);

                // Shrink the Original Image to a thumbnail size.
                imThumbnailImage = OriginalImage.GetThumbnailImage(75, 75, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack), IntPtr.Zero);

                // Save Thumbnail to Memory Stream for Conversion to Byte Array.
                MemoryStream myMS = new MemoryStream();
                imThumbnailImage.Save(myMS, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] test_imge = myMS.ToArray();
                return(test_imge);
            }
            catch (System.Exception)
            {
                return(byteArray);
            }
        }
Exemple #2
0
        public string ConvertThumb(string imgbyte)
        {
            System.Drawing.Image OriginalImage;

            OriginalImage = System.Drawing.Image.FromFile(imgbyte);

            var          imThumbnailImage = OriginalImage.GetThumbnailImage(75, 75, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
            MemoryStream myMS             = new MemoryStream();

            imThumbnailImage.Save(myMS, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] test_imge     = myMS.ToArray();
            string directorypath = Path.Combine(Directory.GetCurrentDirectory(), "Thumbnails");

            if (!Directory.Exists(directorypath))
            {
                Directory.CreateDirectory(directorypath);
            }
            Guid   name     = Guid.NewGuid();
            string filePath = Path.Combine(directorypath, name.ToString() + ".jpeg");

            using (Image image = Image.FromStream(new MemoryStream(test_imge)))
            {
                image.Save(filePath, ImageFormat.Jpeg);
            }
            imThumbnailImage.Dispose();
            OriginalImage.Dispose();
            return(filePath);
        }
Exemple #3
0
        public byte[] Scale(byte[] byteArray)
        {
            try
            {
                int height = 70;
                int width  = 70;
                //Grab the Original Image From SQL
                Image imThumbnailImage;

                Image        OriginalImage;
                MemoryStream ms = new MemoryStream();

                // Stream / Write Image to Memory Stream from the Byte Array.
                ms.Write(byteArray, 0, byteArray.Length);

                OriginalImage = Image.FromStream(ms);

                // Shrink the Original Image to a thumbnail size.
                imThumbnailImage = OriginalImage.GetThumbnailImage(width, height, new Image.GetThumbnailImageAbort(ThumbnailCallBack), IntPtr.Zero);

                // Save Thumbnail to Memory Stream for Conversion to Byte Array.
                MemoryStream myMS = new MemoryStream();
                imThumbnailImage.Save(myMS, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] test_imge = myMS.ToArray();

                // Finally, Update Gallery's Thumbnail.

                imThumbnailImage.Dispose();
                OriginalImage.Dispose();
                return(test_imge);
            }
            catch (Exception ex)
            {
                throw new SystemException("Resize Error.", ex);
            }
        }