Esempio n. 1
0
 internal static void GeneratePostImageResizes(Bitmap sourceBitmap, Size size, int maximumLevel, Action <int, Bitmap> saveAction)
 {
     for (var level = maximumLevel; level >= 0; level--)
     {
         var targetSize = DeepZoomImage.ComputeLevelSize(size, level);
         using (var resizedBitmap = DeepZoomImage.Resize(sourceBitmap, targetSize.Width, targetSize.Height))
         {
             saveAction(level, resizedBitmap);
         }
     }
 }
Esempio n. 2
0
        internal static void SlicePostImage(int postId, Size size, int maximumLevel, string extension, string fileNameIdFormat, ImageFormat imageFormat, int tileSize, int tileOverlap)
        {
            var workingPath = Path.GetFullPath(WorkingFolderName);
            var outputPath  = Path.GetFullPath(OutputFolderName);
            var relativeBinnedImageFolder       = Post.ComputeBinnedPath(postId, null, fileNameIdFormat) + "_files";
            var absoluteBinnedImageFolder       = Path.Combine(workingPath, relativeBinnedImageFolder);
            var absoluteBinnedOutputImageFolder = Path.Combine(outputPath, relativeBinnedImageFolder);

            for (var level = maximumLevel; level >= 0; level--)
            {
                var levelName           = Convert.ToString(level, 10);
                var targetSize          = DeepZoomImage.ComputeLevelSize(size, level);
                var tileFiles           = new List <Stream> ();
                var inputLevelImageFile = Path.ChangeExtension(levelName, extension);
                var inputLevelImagePath = Path.Combine(absoluteBinnedImageFolder, inputLevelImageFile);
                var outputLevelFolder   = Path.Combine(absoluteBinnedOutputImageFolder, levelName);
                Directory.CreateDirectory(outputLevelFolder);

                var tiles = DeepZoomImage.ComputeTiles(targetSize, tileSize, tileOverlap);
                using (var inputStream =
                           new FileStream(inputLevelImagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var levelBitmap = new Bitmap(inputStream))
                    {
                        DeepZoomImage.Slice(levelBitmap, tiles, imageFormat, tileName =>
                        {
                            var tileFileName = Path.ChangeExtension(tileName, extension);
                            var tilePath     = Path.Combine(outputLevelFolder, tileFileName);
                            var stream       =
                                new FileStream(tilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
                            tileFiles.Add(stream);
                            return(stream);
                        }
                                            );
                    }
                foreach (var stream in tileFiles)
                {
                    stream.Close();
                }
            }
        }