我有一个画布,其中有一个文档的位图图像和几个文本框在其上的不同位置。文本框的存在是为了遮挡它后面的文本,但也可能包含顶部的文本(想象一下,遮挡了机密文档中的文本)。这一切都需要保存为tiff文件。
我已经能够很容易地保存图像,然而在顶部保存文本框被证明是真正的挑战。这是我目前所拥有的。
//The document bitmap is the first item in the canvas
foreach (Control redaction in canvas.Children)
{
Size sizeOfControl = new Size(redaction.Width, redaction.Height);
renderBitmap = new RenderTargetBitmap((Int32)sizeOfControl.Width, (Int32)sizeOfControl.Height, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(redaction);
tiffEncoder.Frames.Add(BitmapFrame.Create(frame));
}
FileStream fs = new FileStream(outputFileName, FileMode.Create);
tiffEncoder.Save(fs);
fs.Flush();
fs.Close();当我没有将文档位图添加到tiffEncoder中时,它会保存一个黑色图像,这告诉我它没有正确地转换文本框(或者至少按照我想要的方式)。
那么这是可能的吗?
发布于 2012-01-07 02:47:30
为什么要单独呈现每个控件?此外,您没有使用renderBitmap,而是使用frame来添加编码器(不确定是从哪里来的)。这将渲染画布和画布上的所有控件:
var bm = new RenderTargetBitmap((int)canvas.Width, (int)canvas.Height,
96d, 96d, PixelFormats.Pbgra32);
tiffEncoder.Frames.Add(BitmapFrame.Create(bm));
using (var fs = new FileStream(outputFileName, FileMode.Create))
{
tiffEncoder.Save(fs);
}还要注意,画布必须是可见的(所以窗口不能最小化),否则WPF不会渲染它。
https://stackoverflow.com/questions/8762494
复制相似问题