Esempio n. 1
0
 public static void CreateDZImage(string inputFN, string outputFN)
 {
     ImageCreator creator = new ImageCreator();
     creator.ImageQuality = 0.8;
     creator.TileFormat = ImageFormat.Jpg;
     creator.TileSize = 256;
     creator.TileOverlap = 0;
     creator.Create(inputFN, outputFN);
 }
Esempio n. 2
0
        public string GetDeepZoomImage(string sourceImage, string destinationPath)
        {
            string sourceFileName = Path.GetFileNameWithoutExtension(sourceImage);
            string targetFileName = sourceFileName + ".xml";
            string targetPath = Path.Combine(destinationPath, targetFileName);

            if (!File.Exists(targetPath))
            {
                ImageCreator imageCreator = new ImageCreator();
                imageCreator.ConversionTileFormat = ImageFormat.Jpg;
                imageCreator.ServerFormat = ServerFormats.Default;
                imageCreator.TileFormat = ImageFormat.Jpg;
                imageCreator.Create(sourceImage, targetPath);
            }

            return targetPath;
        }
Esempio n. 3
0
        // Creates the DeepZoom images.
        // Should throw an exception if the DeepZoom creation fails (for instance if the image is broken)
        public static void createDeepZoomImages(artwork aw)
        {
            string imagePath = aw.path;
            string imageName = aw.uniqueName;
            string destFolderPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Images\\DeepZoom";

            ImageCreator ic = new ImageCreator();
            ic.TileFormat = ImageFormat.Jpg;
            ic.TileOverlap = 1;
            ic.TileSize = 256;
            ic.ImageQuality = 0.92;
            ic.UseOptimizations = true;
            Directory.CreateDirectory(destFolderPath + "\\" + imageName);
            string target = destFolderPath + "\\" + imageName + "\\dz.xml";
            ic.Create(imagePath, target);
            ic = null;
            System.GC.Collect();
        }
        private void createDZ_Click(object sender, RoutedEventArgs e)
        {
            String[] strings = Regex.Split(imagePath, imageName);
            String srcFolderPath = strings[0];
            String destFolderPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Images\\DeepZoom";
            ImageCreator ic = new ImageCreator();

            ic.TileFormat = ImageFormat.Jpg;
            ic.TileOverlap = 1;
            ic.TileSize = 256;
            ic.ImageQuality = 0.92;
            Directory.CreateDirectory(destFolderPath + "\\" + imageName);

            string target = destFolderPath + "\\" + imageName + "\\dz.xml";

            ic.Create(imagePath, target);
            MessageBox.Show("Create Deep Zoom image successfully!");
        }
Esempio n. 5
0
        private void DeepZoomDLL_doWork(object sender, DoWorkEventArgs e)
        {
            List <object> genericlist = e.Argument as List <object>;
                string destinationFile = (string) genericlist[0];
                string fNameNoExtension = (string) genericlist[1];
                int txtTileSize = (int) genericlist[2];

                //MessageBox.Show(fNameNoExtension);

                ImageCreator ic = new ImageCreator();
                ic.TileSize = txtTileSize;
                ic.TileOverlap = 1;
                ic.TileFormat = Microsoft.DeepZoomTools.ImageFormat.Png;
                //ic.UseOptimizations = true;
                ic.Create(destinationFile, "output\\" + fNameNoExtension);
        }
        //public CassetteExtension(string path) : base(path)  {  }
        //public CassetteExtension(DirectoryInfo dir, string cassName, string fn, string dn, XElement db) :
        //    base(dir, cassName, fn, dn, db) { }

        /// <summary>
        /// Вычисляет превьюшки для фоток. Режим - набор (подмножество) букв "smn". Возвращает Uri оригинала.
        /// </summary>
        /// <param name="iisstore"></param>
        /// <param name="regimes"></param>
        /// <returns></returns>
        public static Uri MakePhotoPreviews(this Cassette cassette, XElement iisstore, string regimes)
        {
            string ur          = iisstore.Attribute(ONames.AttUri).Value;
            string original    = iisstore.Attribute(ONames.AttOriginalname).Value;
            string filePath    = ur.Substring(ur.Length - 9);
            string imageSource = cassette.Dir.FullName + "/originals/" + filePath + original.Substring(original.LastIndexOf('.'));

            Uri _source = null;

            try
            {
                _source = new Uri(imageSource);
            }
            catch (Exception exc)
            {
                Fogid.Cassettes.LOG.WriteLine(exc.Message + " Не загрузился файл " + iisstore.ToString());
                return(null);
            }

            BitmapImage bi     = new BitmapImage(_source);
            double      width  = (double)bi.PixelWidth;
            double      height = (double)bi.PixelHeight;
            // добавляем информацию в iisstore, вычисляя width и height
            XAttribute att_width = iisstore.Attribute("width");

            if (att_width == null)
            {
                iisstore.Add(new XAttribute("width", width.ToString()));
            }
            else
            {
                att_width.Value = width.ToString();
            }
            XAttribute att_height = iisstore.Attribute("height");

            if (att_height == null)
            {
                iisstore.Add(new XAttribute("height", height.ToString()));
            }
            else
            {
                att_height.Value = height.ToString();
            }
            // Трансформации
            var transformAtt = iisstore.Attribute("transform");

            if (transformAtt == null)
            {
                transformAtt = new XAttribute("transform", ""); iisstore.Add(transformAtt);
            }
            int          nrotations = transformAtt.Value.Length;
            BitmapSource bs         = new TransformedBitmap(bi, new System.Windows.Media.RotateTransform(90 * nrotations));

            double dim = (width > height ? width : height);

            if (regimes.Contains('s'))
            {
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "small", "previewBase")) / dim,
                                       int.Parse(cassette.GetPreviewParameter(iisstore, "small", "qualityLevel")),
                                       cassette.Dir.FullName + "/documents/small/" + filePath + ".jpg");
            }
            if (regimes.Contains('m'))
            {
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "medium", "previewBase")) / dim,
                                       int.Parse(cassette.GetPreviewParameter(iisstore, "medium", "qualityLevel")),
                                       cassette.Dir.FullName + "/documents/medium/" + filePath + ".jpg");
            }
            if (regimes.Contains('n'))
            {
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "normal", "previewBase")) / dim,
                                       int.Parse(cassette.GetPreviewParameter(iisstore, "normal", "qualityLevel")),
                                       cassette.Dir.FullName + "/documents/normal/" + filePath + ".jpg");
            }
            if (regimes.Contains('z'))
            {
                ImageCreator icreator = new ImageCreator {
                    ImageQuality = 0.8
                };
                if (!Directory.Exists(cassette.Dir.FullName + "/documents/deepzoom"))
                {
                    Directory.CreateDirectory(cassette.Dir.FullName + "/documents/deepzoom");
                }
                if (!Directory.Exists(cassette.Dir.FullName + "/documents/deepzoom/" + filePath.Substring(0, 4)))
                {
                    Directory.CreateDirectory(cassette.Dir.FullName + "/documents/deepzoom/" + filePath.Substring(0, 4));
                }
                var destinationPath = cassette.Dir.FullName + "/documents/deepzoom/" + filePath;
                icreator.Create(imageSource, destinationPath + ".xml");
                // тестирование
                Sarc.Create(destinationPath + ".sarc2", new FileSystemInfo[]
                {
                    new FileInfo(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + ".xml"),
                    new DirectoryInfo(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + "_files")
                });
                File.Delete(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + ".xml");
                Directory.Delete(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + "_files", true);


                //if(regimes.Contains("a"))
                //{
                //    Archive.ToArchive.Create(destinationPath+".sarc", new Dictionary<string, string>
                //                                                  {
                //                                                      {destinationPath + "_files",   filePath.Substring(5) + "_files"},
                //                                                      {destinationPath + ".xml", ""}
                //                                                  });
                //}
            }
            return(_source);
        }
Esempio n. 7
0
 private void TileSingleImage(string image, string target)
 {
     ImageCreator ic = new ImageCreator();
     ic.TileSize = 512;
     ic.TileFormat = ImageFormat.Png;
     ic.ImageQuality = 0.92;
     ic.TileOverlap = 0;
     ic.MaxLevel = Convert.ToInt32(Math.Log(ic.TileSize, 2));
     ic.Create(image, target);
 }
Esempio n. 8
0
        public void TileImages()
        {
            if (!Directory.Exists(Up.CollectionDeepzoomPath))
            {
                Directory.CreateDirectory(Up.CollectionDeepzoomPath);
            }

            if (!Directory.Exists(Up.CollectionDeepzoomPath + "_tmp"))
            {
                Directory.CreateDirectory(Up.CollectionDeepzoomPath + "_tmp");
            }


            List<string> images = GetCollectionImages();
            List<string> data = new List<string>();

            //sort by filename
            int offset = 4;
            var sortedFiles = from imgF in images
                              orderby Int32.Parse(imgF.Substring(0, imgF.Length - offset)) ascending
                              select imgF;

            IList<string> sortedFileList = sortedFiles.ToList();
            UpdateProgressBar(0, "Generating Images");

            
            
            int numImages = sortedFiles.Count();
            int updateInterval =  Convert.ToInt32(Math.Ceiling(numImages / 100.0));
            //MessageBox.Show(sortedFiles.Count().ToString());
            
            string timeInterval = DateTime.Now.ToString();
            int count = 0;
            ImageCreator ic = new ImageCreator();
            ic.TileSize = 512;
            ic.TileFormat = ImageFormat.Png;
            ic.ImageQuality = 0.92;
            ic.TileOverlap = 0;
            ic.MaxLevel = Convert.ToInt32(Math.Log(ic.TileSize, 2));
            //Parallel.For(0, numImages, i =>
            for (int i = 0; i < numImages; i++)
            {
                string image = sortedFileList[i];
                if ((count % updateInterval) == 0)
                {
                    int progValue = Convert.ToInt32(Math.Round((double)count / sortedFiles.Count() * 100, 0));
                    UpdateProgressBar(progValue, "Generating Images");
                }
                count++;

                string target = Up.CollectionDeepzoomPath + "\\" + image.Substring(0, (image.Length - 4)) + ".xml";
                data.Add(target);
                ic.Create(Up.CollectionImagePath + "\\" + image, target);
                //TileSingleImage(image, target);
            //});
            }
            timeInterval += "\n" + DateTime.Now.ToString();
            //MessageBox.Show(timeInterval);

            /*
            foreach (string image in sortedFiles)
            {
                string target = Up.CollectionDeepzoomPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(image);
                data.Add(System.IO.Path.ChangeExtension(target, ".xml"));
            }

            
            Parallel.ForEach(sortedFiles, (image, state, count) =>
            {
                int progValue = Convert.ToInt32(Math.Round((double)count / sortedFiles.Count() * 100, 0));
                UpdateProgressBar(progValue, "Generating Images");
                TileSingleImage(image);
            });
            */

            CollectionCreator cc = new CollectionCreator();
            cc.TileSize = 512;
            cc.TileFormat = ImageFormat.Png;
            cc.ImageQuality = 0.92;
            cc.TileOverlap = 0;
            cc.MaxLevel = Convert.ToInt32(Math.Log(cc.TileSize, 2));
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                progressBar1.Visibility = System.Windows.Visibility.Hidden;
                progressText1.Text = "Processing Images";
            }));
            //UpdateProgressBar(0, "Processing Images");
            /*
            Directory.CreateDirectory(Up.CollectionDeepzoomPath + "\\" + Up.CollectionName + "_deepzoom_files");
            Bitmap img1px = new Bitmap(1, 1);
            for (int i = 0; i <= cc.MaxLevel; i++)
            {
                string levelDir = Up.CollectionDeepzoomPath + "\\" + Up.CollectionName + "_deepzoom_files" + "\\" + i.ToString();
                Directory.CreateDirectory(levelDir);
                img1px.Save(levelDir + "\\0_0.png");
            }

            StreamWriter sw = new StreamWriter(Up.CollectionDeepzoomPath + "\\" + Up.CollectionName + "_deepzoom.xml");
            sw.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Collection MaxLevel=\"{0}\" TileSize=\"{1}\" Format=\"{2}\" NextItemId=\"{3}\" ServerFormat=\"{4}\" xmlns=\"http://schemas.microsoft.com/deepzoom/2009\">\n<Items>",
                    cc.MaxLevel,
                    cc.TileSize,
                    cc.TileFormat,
                    data.Count,
                    cc.ServerFormat);
            
            for (int i = 0; i < numImages; i++)
            {
                string image = sortedFileList[i];
                string name = image.Substring(0, (image.Length - 4));
                string xml = name + ".xml";
                sw.WriteLine(
                    "<I Id=\"{0}\" N=\"{0}\" Source=\"{0}.xml\"><Size Width=\"{1}\" Height=\"{1}\" /></I>",
                    name,
                    cc.TileSize
                    );
            }
            sw.WriteLine("</Items>\n</Collection>");
            sw.Close();
            */
            cc.Create(data, Up.CollectionDeepzoomPath + "\\" + Up.CollectionUid + "_deepzoom");
        }
Esempio n. 9
0
        //public CassetteExtension(string path) : base(path)  {  }
        //public CassetteExtension(DirectoryInfo dir, string cassName, string fn, string dn, XElement db) :
        //    base(dir, cassName, fn, dn, db) { }
        /// <summary>
        /// Вычисляет превьюшки для фоток. Режим - набор (подмножество) букв "smn". Возвращает Uri оригинала.
        /// </summary>
        /// <param name="iisstore"></param>
        /// <param name="regimes"></param>
        /// <returns></returns>
        public static Uri MakePhotoPreviews(this Cassette cassette, XElement iisstore, string regimes)
        {
            string ur = iisstore.Attribute(ONames.AttUri).Value;
            string original = iisstore.Attribute(ONames.AttOriginalname).Value;
            string filePath = ur.Substring(ur.Length - 9);
            string imageSource = cassette.Dir.FullName + "/originals/" + filePath + original.Substring(original.LastIndexOf('.'));

            Uri _source = null;
            try
            {
                _source = new Uri(imageSource);
            }
            catch(Exception exc)
            {
                Fogid.Cassettes.LOG.WriteLine(exc.Message + " Не загрузился файл " + iisstore.ToString());
                return null;
            }

            BitmapImage bi = new BitmapImage(_source);
            double width = (double)bi.PixelWidth;
            double height = (double)bi.PixelHeight;
            // добавляем информацию в iisstore, вычисляя width и height
            XAttribute att_width = iisstore.Attribute("width");
            if(att_width == null) iisstore.Add(new XAttribute("width", width.ToString()));
            else att_width.Value = width.ToString();
            XAttribute att_height = iisstore.Attribute("height");
            if(att_height == null) iisstore.Add(new XAttribute("height", height.ToString()));
            else att_height.Value = height.ToString();
            // Трансформации
            var transformAtt = iisstore.Attribute("transform");
            if(transformAtt == null) { transformAtt = new XAttribute("transform", ""); iisstore.Add(transformAtt); }
            int nrotations = transformAtt.Value.Length;
            BitmapSource bs = new TransformedBitmap(bi, new System.Windows.Media.RotateTransform(90 * nrotations));

            double dim = (width > height ? width : height);
            if(regimes.Contains('s'))
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "small", "previewBase")) / dim,
                    int.Parse(cassette.GetPreviewParameter(iisstore, "small", "qualityLevel")),
                    cassette.Dir.FullName + "/documents/small/" + filePath + ".jpg");
            if(regimes.Contains('m'))
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "medium", "previewBase")) / dim,
                    int.Parse(cassette.GetPreviewParameter(iisstore, "medium", "qualityLevel")),
                    cassette.Dir.FullName + "/documents/medium/" + filePath + ".jpg");
            if(regimes.Contains('n'))
                ImageLab.TransformSave(bs, double.Parse(cassette.GetPreviewParameter(iisstore, "normal", "previewBase")) / dim,
                    int.Parse(cassette.GetPreviewParameter(iisstore, "normal", "qualityLevel")),
                    cassette.Dir.FullName + "/documents/normal/" + filePath + ".jpg");
            if(regimes.Contains('z'))
            {
                ImageCreator icreator = new ImageCreator { ImageQuality = 0.8 };
                if(!Directory.Exists(cassette.Dir.FullName + "/documents/deepzoom"))
                    Directory.CreateDirectory(cassette.Dir.FullName + "/documents/deepzoom");
                if(!Directory.Exists(cassette.Dir.FullName + "/documents/deepzoom/" + filePath.Substring(0, 4)))
                    Directory.CreateDirectory(cassette.Dir.FullName + "/documents/deepzoom/" + filePath.Substring(0, 4));
                var destinationPath = cassette.Dir.FullName + "/documents/deepzoom/" + filePath;
                icreator.Create(imageSource, destinationPath + ".xml");
                // тестирование
                Sarc.Create(destinationPath + ".sarc2", new FileSystemInfo[]
                {
                    new FileInfo(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + ".xml"),
                    new DirectoryInfo(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + "_files")
                });
                File.Delete(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + ".xml");
                Directory.Delete(cassette.Dir.FullName + "/documents/deepzoom/" + filePath + "_files", true);

                //if(regimes.Contains("a"))
                //{
                //    Archive.ToArchive.Create(destinationPath+".sarc", new Dictionary<string, string>
                //                                                  {
                //                                                      {destinationPath + "_files",   filePath.Substring(5) + "_files"},
                //                                                      {destinationPath + ".xml", ""}
                //                                                  });
                //}
            }
            return _source;
        }
        /// <summary>
        /// Create deep zoom image here
        /// </summary>
        private void progressBarWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            String[] strings = Regex.Split(imagePath, imageName);
            String srcFolderPath = strings[0];
            String destFolderPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Images\\DeepZoom";

            ImageCreator ic = new ImageCreator();

            ic.TileFormat = ImageFormat.Jpg;
            ic.TileOverlap = 1;
            ic.TileSize = 256;
            ic.ImageQuality = 0.92;
            ic.UseOptimizations = true;
            Directory.CreateDirectory(destFolderPath + "\\" + imageName);

            string target = destFolderPath + "\\" + imageName + "\\dz.xml";

            ic.Create(imagePath, target);
            ic = null;
            System.GC.Collect();
            System.GC.Collect();
            Thread.Sleep(0);
        }