예제 #1
0
        public void GetImages(string path, string dziFolderPath)
        {
            ImageCreator creator = new ImageCreator();

            creator.TileFormat  = ImageFormat.Jpg;
            creator.TileOverlap = 1;
            creator.TileSize    = 256;

            List <string> files = new List <string>();

            foreach (var file in Directory.GetFiles(path))
            {
                files.Add(file);
            }
            ;

            List <string> dzi = new List <string>();

            foreach (var name in files)
            {
                string output = Path.Combine(dziFolderPath + "\\", Path.GetFileNameWithoutExtension(name) + ".dzi");
                dzi.Add(output);
                creator.Create(name, output);
            }

            CollectionCreator ccreator = new CollectionCreator();

            ccreator.TileFormat  = ImageFormat.Jpg;
            ccreator.TileOverlap = 1;
            ccreator.TileSize    = 256;
            ccreator.Create(dzi, Path.Combine(dziFolderPath + "\\", "da.dzc"));
        }
예제 #2
0
 public CollectionConverter(
     CollectionCreator createCollection,
     ITomlSerializerContext context)
 {
     _createCollection = createCollection;
     _itemConverter    = context.GetConverter <TItem>();
 }
        internal virtual bool AddToSet(T item, CollectionCreator <ICollection <T> > fullSetCreator, out object newSet)
        {
            if (this.IndexOf(item) < 0)
            {
                newSet = this.Add(item, fullSetCreator);
                return(true);
            }

            newSet = this;
            return(false);
        }
    /// <summary>
    /// Generate the deep zoom content using a CollectionCreator.
    /// </summary>
    private void CreateDeepZoom()
    {
        CollectionCreator creator = new CollectionCreator();
        List <Image>      images  = new List <Image>();
        XDocument         doc     = XDocument.Load(HttpContext.Current.Server.MapPath("~/ClientBin/GeneratedImages/Metadata.xml"));
        var    imageElements      = doc.Root.Elements("Image");
        double aspectRatio        = double.Parse(doc.Root.Element("AspectRatio").Value);

        //Populates a list of Microsoft.DeepZoomTools.Image objects using the value provided in Metadata.xml.
        foreach (XElement imageElement in imageElements)
        {
            int    zOrder = int.Parse(imageElement.Element("ZOrder").Value);
            double width  = 1d / double.Parse(imageElement.Element("Width").Value);
            images.Add(new Image(HttpContext.Current.Server.MapPath("~/SourceImages/" + imageElement.Element("FileName").Value))
            {
                ViewportWidth  = width,
                ViewportOrigin = new Point(double.Parse(imageElement.Element("x").Value) * -width, double.Parse(imageElement.Element("y").Value) * -width / aspectRatio),
            });
        }
        creator.Create(images, HttpContext.Current.Server.MapPath("~/ClientBin/GeneratedImages/dzc_output"));
    }
 internal abstract object Insert(int index, T item, CollectionCreator <IList <T> > fullSetCreator);
 internal abstract object Add(T item, CollectionCreator <ICollection <T> > fullSetCreator);
예제 #7
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");
        }