【发布时间】:2014-08-19 10:17:46
【问题描述】:
我使用 Bing 映射 WPF 控件创建了一个 WPF 应用程序。 我希望能够只截取 Bing 地图控件。
是用这段代码来做截图的:
// Store the size of the map control
int Width = (int)MyMap.RenderSize.Width;
int Height = (int)MyMap.RenderSize.Height;
System.Windows.Point relativePoint = MyMap.TransformToAncestor(Application.Current.MainWindow).Transform(new System.Windows.Point(0, 0));
int X = (int)relativePoint.X;
int Y = (int)relativePoint.Y;
Bitmap Screenshot = new Bitmap(Width, Height);
Graphics G = Graphics.FromImage(Screenshot);
// snip wanted area
G.CopyFromScreen(X, Y, 0, 0, new System.Drawing.Size(Width, Height), CopyPixelOperation.SourceCopy);
string fileName = "C:\\myCapture.bmp";
System.IO.FileStream fs = System.IO.File.Open(fileName, System.IO.FileMode.OpenOrCreate);
Screenshot.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
fs.Close();
我的问题:
Width 和 Height 似乎是错误的(错误值)。
生成的屏幕截图似乎使用了错误的坐标。
我的截图:
我的期望:
为什么我会得到这个结果? 我在Release模式下试过,没有Visual Studio,结果是一样的。
【问题讨论】:
-
你可以从stackoverflow.com/questions/9094494/…得到一些想法
标签: c# .net wpf screenshot system.drawing