private pix[,] Z_buffer(List <List <Tuple <PointPol, double> > > pixels) { pix[,] buff = new pix[pictureBox1.Width, pictureBox1.Height]; for (int i = 0; i < pictureBox1.Width; ++i) { for (int j = 0; j < pictureBox1.Height; ++j) { buff[i, j] = new pix(int.MaxValue, Color.White); } } int wh = 0; for (int i = 0; i < pixels.Count(); ++i) { foreach (var p1 in pixels[i]) { Point p = p1.Item1.To2D(comboBox3.SelectedItem.ToString()); if (wh + p.X > -1 && wh + p.X < pictureBox1.Width && p.Y > -1 && p.Y < pictureBox1.Height && buff[wh + p.X, p.Y].z > p1.Item2) { buff[wh + p.X, p.Y].z = (int)p1.Item2; buff[wh + p.X, p.Y].c = Color.FromArgb(((i + 1) * 2) % 255, ((i + 1) * 5) % 255, ((i + 1) * 5) % 255); } } } return(buff); }
private Bitmap geraPng() { //verifico o corte int wM = matrix.GetLength(0); int hM = matrix.GetLength(1); int x2 = 0; int y2 = 0; int x1 = wM - 1; int y1 = hM - 1; bool transp = true; List <pix> px = new List <pix>(); for (int i = 0; i < wM; i++) { for (int j = 0; j < hM; j++) { if (matrix[i, j] != 0) { pix p = new pix(); p.x = i; p.y = j; p.cor = matrix[i, j]; px.Add(p); transp = false; if (i < x1) { x1 = i; } if (j < y1) { y1 = j; } if (i > x2) { x2 = i; } if (j > y2) { y2 = j; } } } } if (transp) { x1 = 0; y1 = 0; x2 = wM - 1; y2 = hM - 1; } //algora calculo o size int w = (x2 - x1) + 1; int hreal = (y2 - y1) + 1; int h = Math.Max((y2 - y1) + 1, Properties.Settings.Default.Max); int difH = h - hreal; //agora crio o mini bitmap Bitmap mini = new Bitmap(w, h); Graphics gg = Graphics.FromImage(mini); gg.Clear(Color.Transparent); foreach (pix p in px) { mini.SetPixel(p.x - x1, (p.y - y1) + difH, paleta[p.cor].Color); } //return mini; //agora vou multiplicar pela escala int escala = Properties.Settings.Default.Escala; Bitmap final = new Bitmap(mini.Width * escala, mini.Height * escala); gg = Graphics.FromImage(final); gg.Clear(Color.Transparent); gg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gg.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; gg.DrawImage(mini, new Rectangle(0, 0, final.Width, final.Height), new Rectangle(0, 0, mini.Width, mini.Height), GraphicsUnit.Pixel); gg.Dispose(); return(final); }