當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.CopyFromRenderTarget方法代碼示例

本文整理匯總了C#中Bitmap.CopyFromRenderTarget方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.CopyFromRenderTarget方法的具體用法?C# Bitmap.CopyFromRenderTarget怎麽用?C# Bitmap.CopyFromRenderTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bitmap的用法示例。


在下文中一共展示了Bitmap.CopyFromRenderTarget方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Redraw

        void Redraw()
        {
            if (_renderTarget == null) return;

            var data = _currentData;
            if (_currentData == null) return;

            if (_averagedData == null || _averagedData.Length != data.Length)
            {
                _averagedData = new byte[data.Length];
            }

            const float degrade = 1f;

            for (var i = 0; i < data.Length; i++)
            {
                _averagedData[i] = (byte)(_averagedData[i] * (1.0f - degrade) + data[i] * degrade);
            }

            //for (var i = 0; i < data.Length / 4; i++)
            //{
            //	_averagedData[i * 4] = (byte)(_averagedData[i * 4] * (1.0f - degrade) + data[i * 4] * degrade);
            //	_averagedData[i * 4 + 1] = _averagedData[i * 4];
            //	_averagedData[i * 4 + 2] = _averagedData[i * 4];
            //	_averagedData[i * 4 + 3] = _averagedData[i * 4];
            //}

            data = _averagedData;

            _renderTarget.BeginDraw();

            var width = pictArea.Width;
            var height = pictArea.Height;

            var dataWidth = data.Length;

            var blockWidth = width / dataWidth;
            var blockHeight = height / 256;

            _renderTarget.Clear(Color.FromKnown(Colors.Black, 1));

            for (var i = 0; i < dataWidth; i++)
            {
                var value = data[i];
                var color1 = Color.FromRGB(255, 255 - value, 255 - value);

                using (var brush1 = _renderTarget.CreateSolidColorBrush(color1))
                {
                    _renderTarget.FillRect(brush1,
                        new RectF(
                            new PointF(i * blockWidth, height - value * blockHeight),
                            new PointF((i + 1) * blockWidth, height - (value + 1) * blockHeight)));
                }
            }

            _cache = _renderTarget.CreateBitmap(
                new SizeU((uint)pictArea.Width, (uint)pictArea.Height),
                IntPtr.Zero,
                0,
                new BitmapProperties(new PixelFormat(DxgiFormat.B8G8R8A8_UNORM, AlphaMode.Ignore), 96, 96));

            _cache.CopyFromRenderTarget(
                new PointU(0, 0),
                _renderTarget,
                new RectU(0, 0, (uint)pictArea.Width, (uint)pictArea.Height));

            _renderTarget.EndDraw();
        }
開發者ID:AaronLieberman,項目名稱:ArduinoTinkering,代碼行數:68,代碼來源:FFTVisualizerWindow.cs


注:本文中的Bitmap.CopyFromRenderTarget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。