/// <summary> /// Pixelate will call <see cref="RenderImage"/>. If <see cref="originalImage"/> is null, RenderImage will also return null. /// Else, we'll enable the print controls (they can only be used after a first image has been loaded), show the pixelated image and /// list up to 64 colors and their usage count. /// </summary> /// <remarks> /// The reasons why we only show 64 colors: /// - We don't have that many different post-it colors. /// - If the original image contains too many different colors, the list of <see cref="ColorCountControl"/> objects would grow so big that a <see cref="System.ComponentModel.Win32Exception"/> (Error -2147467259: Error creating window handle) occurs. /// </remarks> private void Pixelate(bool renderGrid = true) { Image rasterized = RenderImage(renderGrid); if (rasterized == null) { _logger.WriteWarning("NULL", "Pixelate", "rasterized image is null"); return; } SuspendLayout(); try { _logger.WriteLine("Starting Pixelation"); printToolStripMenuItem.Enabled = true; //Enable the print methods print2ToolStripMenuItem.Enabled = true; picImage.Image = rasterized; //Set the image pnlColors.Controls.Clear(); //Clear the color count panel. int i = 0; foreach (KeyValuePair <Color, List <Rectangle> > pair in drawList.OrderByDescending(p => p.Value.Count)) { //Order by usage count (most used first) if (pair.Key.A == 0) //ignore full transparency { continue; } ColorCountControl c = new ColorCountControl(); c.Location = new Point(0, i * c.Height); c.Size = new Size(pnlColors.Width, c.Height); c.Color = pair.Key; c.ColorCount = pair.Value.Count; pnlColors.Controls.Add(c); i++; if (i > 63) //Stop when we have reached 64 different colors. { break; } } _logger.WriteLine("Pixelation Done"); } catch (Exception ex) { _logger.WriteError(ex.ToString(), "Pixelate()", ex.Message); } finally { ResumeLayout(); } }
/// <summary> /// Pixelate will call <see cref="RenderImage"/>. If <see cref="originalImage"/> is null, RenderImage will also return null. /// Else, we'll enable the print controls (they can only be used after a first image has been loaded), show the pixelated image and /// list up to 64 colors and their usage count. /// </summary> /// <remarks> /// The reasons why we only show 64 colors: /// - We don't have that many different post-it colors. /// - If the original image contains too many different colors, the list of <see cref="ColorCountControl"/> objects would grow so big that a <see cref="System.ComponentModel.Win32Exception"/> (Error -2147467259: Error creating window handle) occurs. /// </remarks> private void Pixelate(bool renderGrid = true) { Image rasterized = RenderImage(renderGrid); if (rasterized == null) { return; } SuspendLayout(); try { printToolStripMenuItem.Enabled = true; //Enable the print methods print2ToolStripMenuItem.Enabled = true; picImage.Image = rasterized; //Set the image pnlColors.Controls.Clear(); //Clear the color count panel. int i = 0; foreach (KeyValuePair <Color, List <Rectangle> > pair in drawList.OrderByDescending(p => p.Value.Count)) //Order by usage count (most used first) { if (pair.Key.A == 0) //ignore full transparency { continue; } ColorCountControl c = new ColorCountControl(); c.Location = new Point(0, i * c.Height); c.Size = new Size(pnlColors.Width, c.Height); c.Color = pair.Key; c.ColorCount = pair.Value.Count; pnlColors.Controls.Add(c); i++; if (i > 63) //Stop when we have reached 64 different colors. { break; } } } finally { ResumeLayout(); } }