【发布时间】:2011-10-25 17:24:26
【问题描述】:
我正在使用此代码拍摄 wpf 控件的图像:
BitmapEncoder imgEncoder = new PngBitmapEncoder();
RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 150, 150, PixelFormats.Pbgra32);
bmpSource.Render(element);
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (MemoryStream ms = new MemoryStream())
{
imgEncoder.Save(ms);
bytes = ms.ToArray();
ms.Position = 0;
Image i = Image.FromStream(ms);
i.Save(@"C:\" + Guid.NewGuid().ToString() + "LARGE.png");
}
问题是ActualHeight/Width 属性给出了渲染的高度和宽度,即显示的部分。我想保存整个控件的图像,即使某些控件在屏幕上不可见,即它被放置在滚动查看器中。
如何获取控件的完整大小/高度,以便 bmpSource.Render() 将整个控件呈现为图像?
【问题讨论】:
标签: c# wpf image image-processing uielement