- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码:
LinearGradientBrush linGrBrush = new LinearGradientBrush();
linGrBrush.StartPoint = new Point(0,0);
linGrBrush.EndPoint = new Point(1, 0);
linGrBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.0));
linGrBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.5));
linGrBrush.GradientStops.Add(new GradientStop(Colors.White, 1.0));
Rectangle rect = new Rectangle();
rect.Width = 1000;
rect.Height = 1;
rect.Fill = linGrBrush;
rect.Arrange(new Rect(0, 0, 1, 1000));
rect.Measure(new Size(1000, 1));
如果我这样做
myGrid.Children.Add(rect);
然后在窗口上很好地绘制渐变。
我想将此渐变用于其他地方的强度图,因此我需要从中提取像素。为此,我知道我可以使用 RenderTargetBitmap
将其转换为位图。下面是代码的下一部分:
RenderTargetBitmap bmp = new RenderTargetBitmap(
1000,1,72,72,
PixelFormats.Pbgra32);
bmp.Render(rect);
Image myImage = new Image();
myImage.Source = bmp;
为了测试这一点,我这样做:
myGrid.Children.Add(myImage);
但是窗口上什么也没有出现。我做错了什么?
最佳答案
Arrange
必须在 Measure
之后调用,并且 Rect
值应该正确传递。
代替
rect.Arrange(new Rect(0, 0, 1, 1000)); // wrong width and height
rect.Measure(new Size(1000, 1));
你应该做的
var rect = new Rectangle { Fill = linGrBrush };
var size = new Size(1000, 1);
rect.Measure(size);
rect.Arrange(new Rect(size));
var bmp = new RenderTargetBitmap(1000, 1, 96, 96, PixelFormats.Pbgra32);
bmp.Render(rect);
关于c# - RenderTargetBitmap 似乎没有渲染我的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989444/
我有一个带有小图标的 TreeView 显示在数据模板中。我正在尝试使用 RenderTargetBitmap 将 Treeview 保存为 PNG。 图像在小数据集上正确保存。但是,如果数据集变得太
.net 3.5 sp1 中是否有 RenderTargetBitmap 硬件加速模拟? 最佳答案 MSDN论坛上的回答是there is no hardware accelerated altern
我有以下代码: LinearGradientBrush linGrBrush = new LinearGradientBrush(); linGrBrush.Start
您好,我正在使用 PngBitmapEncoder 从 Canvas 在内存中创建图像。 public void CaptureGraphic() { Canvas canvas = new
每当我渲染 Canvas 并清除其子项并将渲染的位图设置为 Canvas 的背景时,RenderTargetBitmap 就会向右下角滑动。 只有 10 个信誉才能插入图片 :(。 WPF:
我正在尝试使用 RenderTargetBitmap 渲染图像每次我从 RenderTargetBitmap 创建一个实例来渲染图像时,内存都会增加,并且完成后内存永远不会释放这是代码: Render
目标 使用 RenderTargetBitmap 截取一个控件(或一组控件)的屏幕截图。 来源: 预期结果: 方法一 这个基本上使用 UIElement 作为 RenderTa
我尝试使用 RenderTargetBitmap 方法生成 300 dpi 图像。 当我尝试使用 RenderTargetBitmap renderTargetBitmap = new RenderT
我的任务是向用户显示其 XPS 文档每一页的缩略图。我需要所有的图像都很小,所以我将 dpi 设置为 72.0 来渲染它们(我用谷歌搜索了 dpi 72.0 的 A4 纸的尺寸是 635x896)。基
我试图创建一些图表图像,但从未在屏幕上显示这些图表。我已经在这方面工作了很长一段时间并尝试了很多不同的事情,但似乎没有任何效果。如果我首先在窗口中显示图表,则代码可以完美运行,但如果我不在窗口中显示它
我正在尝试使用 RenderTargetBitmap 将具有透明背景的 Visual 对象保存到位图... public static RenderTargetBitmap RenderToBitma
我正在尝试从网络摄像头裁剪图像并显示在摄像头预览旁边。 裁剪图像应考虑 3 个方面。 裁剪后的图像输出格式应为VideoFrame 上面的输出 VideoFrame 需要显示(在 XAML 上) 目标
我有一个简单的 WPF 应用程序,我在其中显示一个非常大的图像 (9000x2875),在它上面显示许多小图像 (64x64)。 为此,我有一个带有一个 Image 的 Canvas,然后我以编程方式
我需要创建一个小而简单的 TIFF 图像,它只是白底黑字,作为我们在多个产品中使用的支持库的一部分。 (想想一张简单的收据或存单之类的东西)。我宁愿不必使用任何第三方库,以避免要求我们向使用该库的所有
如何将 RenderTargetBitmap 对象放入 SoftwareBitmap 中?可以获取 RenderTargetBitmap 作为图像源,另一方面我可以使用 SoftwareBitmap
我在后台线程中应用模糊以提高性能。此函数返回一个 RenderTargetBitmap。完成后,我将通过 Dispatcher 调用图像更新并将其作为内容添加到页面中。这是像下面这样完成的:
我正在开发 Windows Phone 8.1 应用程序,我希望将一些 xaml 渲染到图像文件。 来自 this page on the RenderTargetBitmap class ,看来我的
我正在尝试使用 C# 在 UWP 应用程序中捕获 XAML 网格的视频。 我的方法。 1.使用RenderTargetBitmap使用renderTargetBitmap.RenderAsync进行截
我不明白为什么 RenderTargetBitmap 上的 DPI 参数会像它们看起来那样使用。我经常看到通过基于 DPI 调整图像大小来处理非标准 DPI 设置的代码,如下所示: new Rende
我对 WPF 代码中的内存泄漏感到有些困惑。我正在将一些 3D 几何图形渲染到几个 RenderTargetBitmap,然后将其中的每一个渲染到一个大的主 RenderTargetBitmap。但是
我是一名优秀的程序员,十分优秀!