public MappedImage Downscale(int factor) { int scale = (int)Math.Pow(2.0, factor); MappedImage downscaled = new MappedImage(Resolution / scale); for (int y = 0; y < Resolution; y += scale) { for (int x = 0; x < Resolution; x += scale) { int counter = 0; for (int localY = y; localY < y + scale; localY++) { for (int localX = x; localX < x + scale; localX++) { if (Get(localX, localY)) { counter++; } } } if (counter > scale * scale / 2) { downscaled.Set(x / scale, y / scale); } } } return(downscaled); }
private void RefreshCanvas(Canvas canvas, Models.MappedImage mappedImage) { int res = mappedImage.Resolution; canvas.Children.Clear(); for (int i = 0; i < res; i++) { for (int j = 0; j < res; j++) { if (!mappedImage.Get(j, i)) { continue; } DrawPixel(canvas, j, i, res); } } }
private void LoadImage(string path) { fileNameLabel.Content = path; CurrentFile = new FileInfo(path); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(path); bitmap.EndInit(); image.Source = bitmap; image2.Source = bitmap; image3.Source = bitmap; image4.Source = bitmap; image5.Source = bitmap; CurrentMappedImage = new Models.MappedImage(DefaultRes); RefreshAllCanvases(); }
private void MapCanvas(Canvas canvas, Models.MappedImage mappedImage) { int res = DefaultRes; double pixelWidth = canvas.Width / res; double pixelHeight = canvas.Height / res; for (int i = 0; i < res; i++) { for (int j = 0; j < res; j++) { mappedImage.Clear(i, j); } } foreach (Rectangle rect in canvas.Children) { var y = (int)(Canvas.GetTop(rect) / pixelHeight); var x = (int)(Canvas.GetLeft(rect) / pixelWidth); mappedImage.Set(x, y); } }