Пример #1
0
        /// <summary>
        /// Handles the ValueChanged event of the TrackThreshold control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void TrackThreshold_ValueChanged(object sender, EventArgs e)
        {
            if (_sourceTexture == null)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Unfortunately, because the two interfaces are disconnected, we need to ensure that we're not using a resource on the graphics side
                // when we want access to it on the compute side. This needs to be fixed as it can be a bit on the slow side to constantly do this
                // every frame.
                _sobel.Process(_sourceTexture, _outputUav, TrackThickness.Value, TrackThreshold.Value / 100.0f);

                var png = new GorgonCodecPng();
                using (var tempTexture = new GorgonTexture2D(_graphics, new GorgonTexture2DInfo(_outputTexture)
                {
                    Format = BufferFormat.R8G8B8A8_UNorm
                }))
                {
                    _outputTexture.CopyTo(tempTexture);
                    using (IGorgonImage image = tempTexture.ToImage())
                    {
                        png.SaveToFile(image, @"D:\unpak\uav.png");
                    }
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(this, ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }