public void DrawColor(int index) { try { List <Pixel> pixels = bmp.pixels; Bitmap bitmap = new Bitmap(bmp.Width, bmp.Height); Graphics g = Graphics.FromImage(bitmap); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.FillRectangle(colorList.WhiteBrush, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); Rectangle rt = new Rectangle(); Pixel p; ColorTagged color; int cont = 0; for (int i = 0; i < pixels.Count; i++) { p = pixels[i]; color = colorList.GetColorByIndexTable(p.color); if (color.Tag == index) { rt.X = p.x; rt.Y = -p.y + (bitmap.Height - 1); rt.Width = 1; rt.Height = 1; g.FillRectangle(color.Brush, rt); cont++; } //if (i % 1000 == 0 && ProgressChange != null) //{ // ProgressChange(i); //} } ImageRenderFinish?.Invoke(bitmap); } catch (Exception e) { throw e; } }
public void DrawCounter() { try { font = new Font(FontFamily.GenericSansSerif, 3 * (vPixelSize - (rtSize * 2)) / 5, FontStyle.Regular); List <Pixel> pixels = bmp.pixels; //byte[] colorTableBuffer = bmp.colorTable; //colorTag.SetColorTable(colorTableBuffer); //List<Color> colors = new List<Color>(); //colorTag.CurrentColors = colors; //int compHeight = vPixelSize * 2 + colors.Count * (vPixelSize + vPixelSize / 2); //int compHeight = (retSize + VPixelSize) * CalcNumRow(colorTag.Count,3); int width = bmp.Width * VPixelSize; Bitmap colorTable = GeneratePixelTableCount(width); if (colorTable.Width > width) { width = colorTable.Width; } Bitmap bitmap = new Bitmap(width, bmp.Height * vPixelSize + colorTable.Height); Graphics g = Graphics.FromImage(bitmap); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.FillRectangle(colorList.WhiteBrush, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); g.DrawImage(colorTable, 0, 0); colorTable.Dispose(); //for (int i = 0; i < colors.Count; i++) //{ // g.FillRectangle(new SolidBrush(colors[i]), new Rectangle(10 * i, 0, 10, 10)); //} Rectangle rt = new Rectangle(); Rectangle gr = new Rectangle(); Pixel p; ColorTagged color; int colorTagIndex; string text; SizeF textSize; for (int i = 0; i < pixels.Count; i++) { //Debug.WriteLine(i); p = pixels[i]; //if (!colorTag.CurrentColors[p.color].Equals(IgnoredColor)) color = colorList.GetColorByIndexTable(p.color); if (!color.Equals(IgnoredColor)) { rt.X = p.x * vPixelSize; rt.Y = -p.y * vPixelSize + (bitmap.Height - vPixelSize); rt.Width = vPixelSize; rt.Height = vPixelSize; //System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(rt, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); //string text = p.color.ToString("00"); // int colorTagIndex = colorTag.GetTagIndex(colorTag.CurrentColors[p.color]); colorTagIndex = color.Tag; //g.FillRectangle(new SolidBrush(colorTag.CurrentColors[p.color]), rt); g.FillRectangle(color.Brush, rt); //g.DrawString(text, font, colorTag.CorrectBrush(colorTagIndex), rt.Left + (rt.Width / 2 - textSize.Width / 2), rt.Top + (rt.Height / 2 - textSize.Height / 2)); if (tags) { text = colorTagIndex.ToString(); textSize = g.MeasureString(text, font); g.DrawString(text, font, color.TextBrush, rt.Left + (rt.Width / 2 - textSize.Width / 2), rt.Top + (rt.Height / 2 - textSize.Height / 2)); } if (grid) { //retangulo do topo gr.X = rt.X; gr.Y = rt.Y; gr.Width = rt.Width; gr.Height = rtSize; g.FillRectangle(colorList.BlackBrush, gr); //retangulo da esquerda gr.X = rt.X; gr.Y = rt.Y; gr.Width = rtSize; gr.Height = rt.Height; g.FillRectangle(colorList.BlackBrush, gr); //Retangulo da base gr.X = rt.X; gr.Y = rt.Y + rt.Height - rtSize; gr.Width = rt.Width; gr.Height = rtSize; g.FillRectangle(colorList.WhiteBrush, gr); //Retangulo da direito gr.X = rt.X + rt.Width - rtSize; gr.Y = rt.Y; gr.Width = rtSize; gr.Height = rt.Height; g.FillRectangle(colorList.WhiteBrush, gr); } // bitmap.UnlockBits(bitmapData); } if (i % 1000 == 0 && ProgressChange != null) { ProgressChange(i); } } //GeneratePixelTableCount(colorTag.CurrentColors, g); ImageRenderFinish?.Invoke(bitmap); } catch (Exception e) { throw e; } }