public XIRImage(int id, float aspectRatio, string address, string modified, Dimensions dimensions) { this.id = id; this.address = address; this.aspectRatio = aspectRatio; this.modified = modified; this.dimensions = dimensions; pixTechs = new List<XIRPixelationTechnique>(); }
public XIRImage(XmlElement element) { id = int.Parse(element.GetAttribute("image_id")); aspectRatio = float.Parse(element.GetAttribute("aspectRatio")); address = element.GetElementsByTagName("address")[0].InnerText; modified = element.GetElementsByTagName("modified")[0].InnerText; dimensions = new Dimensions(); XmlElement dimElem = (XmlElement)element.GetElementsByTagName("dimensions")[0]; dimensions.width = int.Parse(dimElem.GetAttribute("width")); dimensions.height = int.Parse(dimElem.GetAttribute("height")); pixTechs = new List<XIRPixelationTechnique>(); XmlNodeList pixElems = element.GetElementsByTagName("pixelationTechnique"); for (int i = 0; i < pixElems.Count; i++) { pixTechs.Add(new XIRPixelationTechnique((XmlElement)pixElems[i])); } }
public static List<Point> CopyImageToAllLocations(SortedList<float, int>[] solutionSet, List<Point> alreadyRendered, Bitmap bmp, Point start, int xCells, int yCells, Dimensions outputDimensions, XIRImage image, Bitmap destination) { int currentID, targetID = image.id; int width = outputDimensions.width; int height = outputDimensions.height; float boxX = (1.0f * width) / xCells; float boxY = (1.0f * height) / yCells; int xActual, yActual; Size currSize = new Size(); float xLoc, yLoc; List<Point> renderedLocations = new List<Point>(0); int avgGrayDiff; for (int x = start.X; x < xCells; x++) { for (int y = start.Y; y < yCells; y++) { currentID = solutionSet[x * yCells + y].Values[0]; avgGrayDiff = XIR.Instance.AverageGrayDiffArray[x * yCells + y]; if (targetID == currentID && !alreadyRendered.Contains(new Point(x,y))) { xLoc = boxX * x; yLoc = boxY * y; xActual = (int)Math.Round(xLoc); yActual = (int)Math.Round(yLoc); currSize.Width = (xLoc + boxX >= width) ? width - xActual - 1 : (int)Math.Round(boxX + xLoc) - xActual; currSize.Height = (yLoc + boxY >= height) ? height - yActual - 1 : (int)Math.Round(boxY + yLoc) - yActual; if (bmp.Size == currSize) { CopyImageInto(destination, bmp, xActual, yActual, avgGrayDiff); renderedLocations.Add(new Point(x, y)); } } } } return renderedLocations; }
public static Bitmap GenerateSolutionImage(SortedList<float, int>[] solutionSet, int xCells, int yCells, Dimensions outputDimensions, bool isGrayscale, ProgressBar progressBar) { Bitmap output = new Bitmap(outputDimensions.width, outputDimensions.height); Bitmap image; int width = outputDimensions.width; int height = outputDimensions.height; float boxX = (1.0f * width) / xCells; float boxY = (1.0f * height) / yCells; float xLoc = 0; float yLoc = 0; int id, imageMatchId, xActual, yActual; IList<int> SortedImageIds; List<Point> renderedLocations = new List<Point>(); List<Point> tmpLocs; int currWidth, currHeight; for (int x = 0; x < xCells; x++) { for (int y = 0; y < yCells; y++) { if (!PointListContains(renderedLocations, new Point(x, y))) { id = 0; SortedImageIds = solutionSet[x * yCells + y].Values; do { imageMatchId = SortedImageIds[id++]; image = XIR.Instance.GetBitmapFromImageId(imageMatchId); } while (image == null); xLoc = boxX * x; yLoc = boxY * y; xActual = (int)Math.Round(xLoc); yActual = (int)Math.Round(yLoc); currWidth = (xLoc + boxX >= width) ? width - xActual - 1 : (int)Math.Round(boxX + xLoc) - xActual; currHeight = (yLoc + boxY >= height) ? height - yActual - 1 : (int)Math.Round(boxY + yLoc) - yActual; image = new Bitmap(image, new Size(currWidth, currHeight)); image = (isGrayscale) ? ConvertImageToGrayscale(image) : image; tmpLocs = FilterHelper.CopyImageToAllLocations(solutionSet, renderedLocations, image, new Point(x, y), xCells, yCells, outputDimensions, XIR.Instance[imageMatchId], output); renderedLocations.AddRange(tmpLocs); image.Dispose(); progressBar.Value += (tmpLocs.Count + progressBar.Value <= progressBar.Maximum) ? tmpLocs.Count : 0; } } } return output; }