我不明白为什么DPI参数的RenderTargetBitmap使用方式与它们的使用方式相同.通常我会通过调整基于DPI的图像大小来查看处理非标准DPI设置的代码,如下所示:
new RenderTargetBitmap ((int) (width/96d)*dpi, (int) (height/96d)*dpi, dpi, dpi, PixelFormats.Pbgra32);
Run Code Online (Sandbox Code Playgroud)
例子:
http://blogs.msdn.com/b/jaimer/archive/2009/07/03/rendertargetbitmap-tips.aspx
ContentControl + RenderTargetBitmap +空图像
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/984da366-33d3-4fd3-b4bd-4782971785f8/
其他时候,dpi似乎被硬编码为96或不同的值,如下所示:
new RenderTargetBitmap (width, height, 96, 96, PixelFormats.Pbgra32);
Run Code Online (Sandbox Code Playgroud)
例子:
http://www.ericsink.com/wpf3d/3_Bitmap.html
http://dedjo.blogspot.com/2008/05/performance-appliance-of.html
如何将已检查的CheckBox(Aero主题)渲染为RenderTargetBitmap?
要么
new RenderTargetBitmap (width, height, 120, 96, PixelFormats.Pbgra32);
Run Code Online (Sandbox Code Playgroud)
例子:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
你什么时候做一个又一个?
如果您以后想要显示与应用程序内部控件大小相同的图像,我是否应该总是调整位图的大小(如第一个示例中所示)?
并且你可能应该在96保存到文件时使用固定dpi,或者如果你使用不同的dpi而不调整宽度和高度?
假设我想将控件的图像保存到具有固定大小的文件.我还能设置dpi还是只使用默认的96?
我无法理解为什么这不起作用,或者我需要它才能使它工作.
要重新编写,请创建一个简单的WPF应用程序并替换主窗口的构造函数:
public MainWindow()
{
InitializeComponent();
// simple visual definition
var grid = new Grid { Width = 300, Height = 300 };
var text = new TextBlock
{
Text = "Y DON'T I WORK???",
FontSize = 100,
FontWeight =
FontWeights.Bold
};
grid.Children.Add(text);
// update the layout so everything is awesome cool
grid.Measure(grid.DesiredSize);
grid.Arrange(new Rect(grid.DesiredSize));
grid.UpdateLayout();
// create a BitmapSource from the visual
var rtb = new RenderTargetBitmap(
(int)grid.Width,
(int)grid.Height,
96,
96,
PixelFormats.Pbgra32);
rtb.Render(grid);
// Slap it in the window …Run Code Online (Sandbox Code Playgroud) 我正在为Windows Phone 8.1编写应用程序.
我需要将UIElement保存为图像文件(我更喜欢JPG或PNG).我正在使用RenderTargetBitmap类来执行此操作.在我的UIElement上调用RenderAsync方法之后,我创建了一个IBuffer,它包含了RenderTargetBitmap方法GetPixelsAsync()的结果.
现在我需要调用方法ToArray()来转换字节数组中的IBuffer以使用类似BitmapEncoder的方式保存我的图像,但似乎在Windows Phone 8.1上没有任何用于IBuffer的ToArray()方法,而在Windows上8.1存在.
我该如何解决这个问题?
我想将一个3D场景从Viewport3D导出到位图.
显而易见的方法是使用RenderTargetBitmap - 但是当我这样做时,导出的位图的质量明显低于屏幕上的图像.环顾四周,似乎RenderTargetBitmap没有利用硬件渲染.这意味着渲染在第0层完成.这意味着没有mip-mapping等,因此降低了导出图像的质量.
有谁知道如何以屏幕质量导出Viewport3D的位图?
澄清
虽然下面给出的示例没有显示这一点,但我最终需要将Viewport3D的位图导出到文件中.据我所知,唯一的方法是将图像转换为从BitmapSource派生的东西.下面的Cplotts显示使用RenderTargetBitmap提高导出质量可以改善图像,但由于渲染仍然在软件中完成,因此速度极慢.
有没有办法使用硬件渲染将渲染的3D场景导出到文件?当然应该可以吗?
你可以看到这个xaml的问题:
<Window x:Class="RenderTargetBitmapProblem.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="400" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Viewport3D Name="viewport3D">
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,3"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-1,-10,0 1,-10,0 -1,20,0 1,20,0"
TextureCoordinates="0,1 0,0 1,1 1,0"
TriangleIndices="0,1,2 1,3,2"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="http://www.wyrmcorp.com/galleries/illusions/Hermann%20Grid.png"
TileMode="Tile" Viewport="0,0,0.25,0.25"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
<ModelVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="-82"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</ModelVisual3D.Transform>
</ModelVisual3D>
</Viewport3D>
<Image Name="rtbImage" Visibility="Collapsed"/> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用WPF转换XPS.
想法是这些图像可以加载silverlight 4,为此我使用以下代码:
// XPS Document
XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
// The number of pages
PageCount = docSeq.References[0].GetDocument(false).Pages.Count;
DocumentPage sizePage = docSeq.DocumentPaginator.GetPage(0);
PageHeight = sizePage.Size.Height;
PageWidth = sizePage.Size.Width;
// Scale dimensions from 96 dpi to 600 dpi.
double scale = 300/ 96;
// Convert a XPS page to a PNG file
for (int pageNum = 0; pageNum < PageCount; pageNum++)
{
DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
BitmapImage bitmap = new BitmapImage();
RenderTargetBitmap renderTarget =
new …Run Code Online (Sandbox Code Playgroud) 我有一个TreeView,数据模板中显示了小图标.我正在尝试使用RenderTargetBitmap将Treeview保存为PNG.
图像可以正确保存在小数据集上.但是,如果数据集变得太大,则会从最终图像中排除某些图标.神奇的数字似乎是200项.如果树是深的还是宽的,似乎没关系,在200个项目之后,图标不会被渲染.
添加了代码
所以这是我用于创建图像的代码.
RenderTargetBitmap targetBitmap = new RenderTargetBitmap(
(int)_treeView.ActualWidth,
(int)_treeView.ActualHeight,
96, 96, PixelFormats.Default);
targetBitmap.Render(_treeView);
Run Code Online (Sandbox Code Playgroud)
添加了屏幕截图
现在,如果我折叠了几个分支,从而隐藏了一些其他图标,那么这些图标就包括在内.它几乎像RenderTargetBitmap.Render无法渲染所有图标.或者它可能与虚拟面板有关.

该RenderTargetBitmap简单的帆布+ InkManager(在Windows 8.1)的工作类别,呈现墨水笔划的图像.UWP推出了InkCanvas和一个新的Inking API.但是,它似乎RenderTargetBitmap不起作用.当我尝试使用RenderAsync方法捕获墨迹笔划时,没有墨迹笔划仅渲染其他对象,如Rectangle等.
这是一个错误还是这个新的API不是以这种方式使用的?如果没有,那我怎样才能渲染图像InkCanvas?
谢谢!
我有一个DrawingContext(Visual或DrawingGroup的一部分),我在其中绘制一堆矩形和/或1位图像.可以将其视为屏蔽1位图像.我想将其转换为位图图像文件.
使用RenderTargetBitmap不是一个选项,因为它只能以32位像素格式渲染,所以如果我必须渲染一个20MB的1位图像,我的堆上最终会得到640MB(20*32)的内存.这当然会产生宏伟的LOH碎片,并且应用程序在第二次拍摄时会耗尽内存.
所以,我基本上需要一种方法来有效地从绘图上下文中写入1位位图文件.任何想法/建议/替代方法将不胜感激.
我有一个RenderTargetBitmap,我需要将其转换为BitmapImage.请检查以下代码.
RenderTargetBitmap bitMap = getRenderTargetBitmap();
Image image = new Image();// This is a Image
image.Source = bitMap;
Run Code Online (Sandbox Code Playgroud)
在上面的代码中我使用了Image.Now我需要使用BitmapImage.我怎样才能做到这一点?
RenderTargetBitmap bitMap = getRenderTargetBitmap();
BitmapImage image = new BitmapImage();// This is a BitmapImage
// how to set bitMap as source of BitmapImage ?
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序依赖于深度缩放图像(从PNG转换为各种规模的JPG金字塔),我们使用DeepZoomTools.dll.这是依赖于PresentationCore.dll并且多年来一直运行良好.
在KB4040972和KB4040973的推出之后,从PNG到JPG的转换生成(取决于坐标)黑色图像而不是它应包含的图像.
如果以下代码在控制台或桌面应用程序中运行,则可以正常运行.
如果在高权限SYSTEM帐户下运行(例如,从任务计划程序),它只能起作用.
我创建了一个重现问题的项目,代码如下:
public static void TestConvert2(string strFileName, string strOutFileName) {
JpegBitmapEncoder jpegBitmapEncoder = new JpegBitmapEncoder();
jpegBitmapEncoder.QualityLevel = 1 + (int) Math.Round(0.95 * 99.0);
BitmapEncoder encoder = jpegBitmapEncoder;
Int32Rect inputRect = new Int32Rect(0, 0, 255, 255);
Rect outputRect = new Rect(0, 0, 255, 255);
Uri bitmapUri = new Uri(strFileName, UriKind.RelativeOrAbsolute);
BitmapDecoder bitmapDecoder = BitmapDecoder.Create(bitmapUri,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
bitmapDecoder = BitmapDecoder.Create(bitmapUri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
BitmapSource inputFrame = (BitmapSource) bitmapDecoder.Frames[0];
BitmapSource source1 = (BitmapSource) new CroppedBitmap(inputFrame, inputRect);
DrawingVisual drawingVisual = new DrawingVisual(); …Run Code Online (Sandbox Code Playgroud)