Esempio n. 1
0
        public void FillRuleTest()
        {
            int scale = 1;

            var bmp = new MemoryBitmap <Pixel.BGR24>(16 * scale, 8 * scale);

            for (int y = 0; y < bmp.Height; ++y)
            {
                for (int x = 0; x < bmp.Width; ++x)
                {
                    var z = ((x / scale) & 1) ^ ((y / scale) & 1);
                    if (z == 1)
                    {
                        bmp.SetPixel(x, y, Pixel.GetColor <Pixel.BGR24>(System.Drawing.Color.DarkGray));
                    }
                }
            }

            var dc = bmp.CreateDrawingContext();

            foreach (var tri in _Triangle.GetFillRuleTriangles())
            {
                dc.DrawPolygon(System.Drawing.Color.Red, tri.A * scale, tri.B * scale, tri.C * scale);
            }

            bmp.Save(new AttachmentInfo("result.png"));
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            MemoryBitmap mbp    = new MemoryBitmap(new Bitmap(pictureBox1.Image));
            MemoryBitmap output = new MemoryBitmap(new Bitmap(pictureBox1.Image));

            int[] xModel = new int[] { 1, 1, 1, 0, 0, 0, -1, -1, -1 };
            int[] yModel = new int[] { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
            mbp.Gray();

            for (int i = 0; i < mbp.Height; i++)
            {
                for (int j = 0; j < mbp.Width; j++)
                {
                    int index = 0;
                    int Gx = 0, Gy = 0;
                    for (int m = -1; m < 2; m++)
                    {
                        for (int n = -1; n < 2; n++)
                        {
                            int vx = j + n >= mbp.Width ? j * 2 - mbp.Width : j + n;
                            int vy = i + m >= mbp.Height ? i * 2 - mbp.Height : i + m;


                            if (vx < 0)
                            {
                                vx *= -1;
                            }
                            if (vy < 0)
                            {
                                vy *= -1;
                            }

                            int val = mbp.GetPixel(vx, vy).R;
                            Gx += val * xModel[index];
                            Gy += val * yModel[index];
                            index++;
                        }
                    }
                    Gx = Math.Abs(Gx);
                    Gy = Math.Abs(Gy);
                    int p = Math.Max(Gx, Gy);
                    output.SetPixel(j, i, p, p, p);
                }
            }
            output.SaveMemory();
            pictureBox2.Image = output.bmp;
        }
Esempio n. 3
0
        public static MemoryBitmap <Vector3> CreateBGRBitmap(SpanTensor3 <Single> tensor, Func <Single[], Vector3> pixelFunc)
        {
            var midPixel = new Single[tensor.Dimensions[2]];

            var memory = new MemoryBitmap <Vector3>(tensor.Dimensions[1], tensor.Dimensions[0], Pixel.BGR96F.Format);

            for (int y = 0; y < tensor.Dimensions[0]; ++y)
            {
                var row = tensor[y];

                for (int x = 0; x < row.Dimensions[0]; ++x)
                {
                    row[x].CopyTo(midPixel);
                    var dstPixel = pixelFunc(midPixel);
                    memory.SetPixel(x, y, dstPixel);
                }
            }

            return(memory);
        }