有没有办法打印wpf窗口的截屏?
我尝试了很多东西,但要么是A4尺寸太大,要么因为没有设置边距而裁剪掉了。 这里是我试过的代码:
的Sample1:
private void btnPrintStanzbild_Click(object sender, RoutedEventArgs e)
{
Visual target = gRight;
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
RenderTargetBitmap renderTarget = new RenderTargetBitmap((Int32)bounds.Width, (Int32)bounds.Height, 96, 96, PixelFormats.Pbgra32);
DrawingVisual visual = new DrawingVisual();
using (DrawingContext context = visual.RenderOpen())
{
VisualBrush visualBrush = new VisualBrush(target);
context.DrawRectangle(visualBrush, null, new Rect(new Point(), bounds.Size));
}
renderTarget.Render(visual);
PngBitmapEncoder bitmapEncoder = new PngBitmapEncoder();
BitmapImage bi = new BitmapImage();
bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
using (MemoryStream stm = new MemoryStream())
{
bitmapEncoder.Save(stm);
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = stm;
bi.EndInit();
}
var vis = new DrawingVisual();
var dc = vis.RenderOpen();
dc.DrawImage(bi, new Rect { Width = bi.Width, Height = bi.Height });
dc.Close();
var pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true)
{
var queue = pdialog.PrintQueue;
var area = queue.GetPrintCapabilities(pdialog.PrintTicket)
.PageImageableArea;
pdialog.PrintVisual(vis, "My Image");
}
}
样品2:
PrintDialog pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true)
{
var queue = pdialog.PrintQueue;
var area = queue.GetPrintCapabilities(pdialog.PrintTicket)
.PageImageableArea;
pdialog.PrintVisual(this, "My Image");
}
样本3:
答案 0 :(得分:0)
select t.*
into <local_table>
from <remote_link>.<database>.<schema>.<table>;