SetPixel() public method

Sets the pixel color at the specified position.
Note that this method can be extremely slow to set each pixel of a bitmap. If you need better performance, use Lock to get access to the bitmap's pixel buffer directly, then optionally use BitmapData.SetPixel(Point,Color) to set each pixel value.
public SetPixel ( Point position, Color color ) : void
position Point Position to set the pixel color.
color Color Color to set.
return void
Exemplo n.º 1
0
        public void RenderScene(string scenename)
        {
            var dev = Device.FirstGpu;

            Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description);

            var scene_params = new SceneParameters(Client, ShadingSystem.SVM, BvhType.Static, false, false, false);
            var scene        = new Scene(Client, scene_params, dev);

            var xml = new CSyclesXmlReader(Client, scenename);

            xml.Parse(false);
            var width  = (uint)scene.Camera.Size.Width;
            var height = (uint)scene.Camera.Size.Height;

            var session_params = new SessionParameters(Client, dev)
            {
                Experimental      = false,
                Samples           = (int)samples,
                TileSize          = new Size(64, 64),
                StartResolution   = 64,
                Threads           = (uint)(dev.IsCpu ? 0 : 0),
                ShadingSystem     = ShadingSystem.SVM,
                Background        = true,
                ProgressiveRefine = false,
                Progressive       = false,
                TileOrder         = TileOrder.HilbertSpiral
            };
            var Session = new Session(Client, session_params, scene);

            Session.Reset(width, height, samples);

            g_write_render_tile_callback = WriteRenderTileCallback;
            Session.WriteTileCallback    = g_write_render_tile_callback;

            /*if (!silent)
             * {
             *      Session.UpdateCallback = g_update_callback;
             *      Session.UpdateTileCallback = g_update_render_tile_callback;
             *      Session.WriteTileCallback = g_write_render_tile_callback;
             * }
             * CSycles.set_logger(Client.Id, g_logger_callback);
             */

            Session.Start();
            Session.Wait();

            uint bufsize;
            uint bufstride;

            CSycles.session_get_buffer_info(Client.Id, Session.Id, out bufsize, out bufstride);
            var pixels = CSycles.session_copy_buffer(Client.Id, Session.Id, bufsize);

            var bmp = new ed.Bitmap((int)width, (int)height, Eto.Drawing.PixelFormat.Format32bppRgba);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var i = y * (int)width * 4 + x * 4;
                    bmp.SetPixel(x, y, new ed.Color(Math.Min(pixels[i], 1.0f), Math.Min(pixels[i + 1], 1.0f), Math.Min(pixels[i + 2], 1.0f), Math.Min(pixels[i + 3], 1.0f)));
                }
            }
            bmp.Save("test.png", Eto.Drawing.ImageFormat.Png);

            Result = bmp;

            Session.Destroy();

            Console.WriteLine("Cleaning up :)");
        }
Exemplo n.º 2
0
        public void RenderScene(string scenename)
        {
            var dev = Device.FirstGpu;
            Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description);

            var scene_params = new SceneParameters(Client, ShadingSystem.SVM, BvhType.Static, false, false, false);
            var scene = new Scene(Client, scene_params, dev);

            var xml = new CSyclesXmlReader(Client, scenename);
            xml.Parse(false);
            var width = (uint)scene.Camera.Size.Width;
            var height = (uint)scene.Camera.Size.Height;

            var session_params = new SessionParameters(Client, dev)
            {
                Experimental = false,
                Samples = (int) samples,
                TileSize = new Size(64, 64),
                StartResolution = 64,
                Threads = (uint)(dev.IsCpu ? 0 : 0),
                ShadingSystem = ShadingSystem.SVM,
                Background = true,
                ProgressiveRefine = false,
                Progressive = false,
                TileOrder = TileOrder.HilbertSpiral
            };
            var Session = new Session(Client, session_params, scene);
            Session.Reset(width, height, samples);

            g_write_render_tile_callback = WriteRenderTileCallback;
            Session.WriteTileCallback = g_write_render_tile_callback;

            /*if (!silent)
            {
                Session.UpdateCallback = g_update_callback;
                Session.UpdateTileCallback = g_update_render_tile_callback;
                Session.WriteTileCallback = g_write_render_tile_callback;
            }
            CSycles.set_logger(Client.Id, g_logger_callback);
            */

            Session.Start();
            Session.Wait();

            uint bufsize;
            uint bufstride;
            CSycles.session_get_buffer_info(Client.Id, Session.Id, out bufsize, out bufstride);
            var pixels = CSycles.session_copy_buffer(Client.Id, Session.Id, bufsize);

            var bmp = new ed.Bitmap((int)width, (int)height, Eto.Drawing.PixelFormat.Format32bppRgba);
            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var i = y * (int)width * 4 + x * 4;
                    bmp.SetPixel(x, y, new ed.Color(Math.Min(pixels[i], 1.0f), Math.Min(pixels[i + 1], 1.0f), Math.Min(pixels[i + 2], 1.0f), Math.Min(pixels[i + 3], 1.0f)));
                }
            }
            bmp.Save("test.png", Eto.Drawing.ImageFormat.Png);

            Result = bmp;

            Session.Destroy();

            Console.WriteLine("Cleaning up :)");
        }