本文整理汇总了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();
}