示例#1
0
        public Collage(string templateImageLocation, string imagesLocation, ImageSize scale = ImageSize.Medium, CollageSize collageSize = CollageSize.Medium)
        {
            ImageSize   = scale;
            CollageSize = collageSize;
            Image i = ImageFileIO.ImageFromFile(templateImageLocation);

            //Template = new CollageTemplateImage(i, templateScale);
            Template = new CollageTemplateImage(i, ImageSize, CollageSize);

            string[] fileNames = ImageFileIO.GetAllImagesFromFolder(imagesLocation);
            ImagePaths = fileNames.ToArray();
            //Image[] images = new Image[fileNames.Count()];

            //for (int j = 0; j < fileNames.Count(); ++j)
            //{
            //    images[j] = ImageFileIO.ImageFromFile(fileNames.ElementAt(j));
            //}

            CollageImages = new CollageImage[fileNames.Count()];
            Console.WriteLine("Calculating average image values...");
            for (int j = 0; j < fileNames.Count(); ++j)
            {
                //CollageImage ci = new CollageImage(images[j], Image_Scale);
                CollageImage ci = new CollageImage(fileNames[j], (int)ImageSize);
                CollageImages[j] = ci;
                Console.WriteLine("avg value: " + ci.ColorValues.AvgRGB + "   Count = " + j);
            }
            Console.WriteLine("Done with image values");
            Array.Sort(CollageImages);
        }
        /// <summary>
        /// Recieves an image, generates a table of average rgb values for each pixel
        /// </summary>
        /// <param name="template"></param>
        //public CollageTemplateImage(Image templateImage)
        //{
        //    TemplateImage = templateImage;
        //    TemplateValues = new double[templateImage.Height, templateImage.Width];
        //    GenerateTemplateValues();
        //}

        public CollageTemplateImage(Image template, ImageSize imageSize, CollageSize size = CollageSize.Medium)
        {
            int    longSide  = Math.Max(template.Height, template.Width);
            int    maxPixels = (int)((double)size / (double)imageSize);
            double scaleby   = ((double)maxPixels / (double)longSide);
            Image  scaled    = ImageFormatter.ScaleImage(template, scaleby, scaleby);

            //if (scaled.Height > MaxHeightWidth || scaled.Width > MaxHeightWidth)
            //{
            //    double scaleBy = Math.Max(scaled.Height, scaled.Width);
            //    double newScale = MaxHeightWidth / scaleBy;
            //    scaled = ImageFormatter.ScaleImage(scaled, newScale, newScale);
            //}
            TemplateImage  = scaled;
            TemplateValues = new ColorValue[TemplateImage.Height, TemplateImage.Width];
            GenerateTemplateValues();
        }