c# - 如何从 ActiveX 组件中保存位图
问题描述
尝试保存 AxMsTscAxNotSafeForScripting(Microsoft 终端服务客户端控件)的屏幕,但找不到任何有关它的信息...
我尝试了一个代码,但它只筛选元素字段... https://i.imgur.com/fo6jKDT.png
[Flags]
private enum DrawingOptions
{
PRF_CHECKVISIBLE = 0x00000001,
PRF_NONCLIENT = 0x00000002,
PRF_CLIENT = 0x00000004,
PRF_ERASEBKGND = 0x00000008,
PRF_CHILDREN = 0x00000010,
PRF_OWNED = 0x00000020
}
private const uint WM_PAINT = 0xF;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr dc, DrawingOptions opts);
var bm = new Bitmap(rdp.Width, rdp.Height, rdp.CreateGraphics());
using (Graphics g = Graphics.FromImage(bm))
{
IntPtr dc = g.GetHdc();
try
{
SendMessage(rdp.Handle, WM_PAINT, dc,
DrawingOptions.PRF_CLIENT |
DrawingOptions.PRF_NONCLIENT |
DrawingOptions.PRF_CHILDREN);
}
finally
{
g.ReleaseHdc();
}
}
pictureBox1.Image = bm;
解决方案
此代码有助于保存表单图像并完美显示 ActiveX。由于该项目是静态的,我将只裁剪图像并获得我想要的屏幕截图。
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);
public static Bitmap PrintWindow(IntPtr hwnd)
{
RECT rc;
GetWindowRect(hwnd, out rc);
Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();
PrintWindow(hwnd, hdcBitmap, 0);
gfxBmp.ReleaseHdc(hdcBitmap);
gfxBmp.Dispose();
return bmp;
}
推荐阅读
- java - 文件未从某些 HTTP URL 下载
- ruby - 如何测试使用 rspec 进行 HTTP POST 调用的 ruby 函数?
- matplotlib - Colorbar 科学记数法,将 e^ 改为 10^
- selenium - 量角器获取控制台变量值
- php - 插件子 Wordpress
- python - networkx 在 add_edges_frim 中使用字符串
- python-3.x - 将多个 CSV 文件合并到单个文件中,并在第一列中添加每个 csv 的列名
- python - fbprophet:预测未来的假期
- security - 迁移身份提供者,保留用户 ID 和迁移策略(Auth 0 等)
- laravel-5 - Laravel 5 访问会话用户