如何发送要在 Paint 中编辑的图片框的内容?
我想过快速暂时保存它,然后发送要加载的临时地址,但我认为这会导致一些小的保存问题。
不幸的是我现在用 C# 提供答案。幸运的是,只是语法而不是内容需要改变。
假设这是您的图片框控件,获取内容(作为位图)并将其放在剪贴板上。现在,如果您将其设置为前台等,您可以将其粘贴到 MSPaint 中,但您可以使用 SendMessage 或 SendKeys 进行粘贴。
Bitmap bmp = new Bitmap(pictureBox1.Image);
Clipboard.SetData(System.Windows.Forms.DataFormats.Bitmap, bmp);
一个糟糕的例子,可以选择打开 mspaint 并等待它出现,使用 SendKeys 进行粘贴。
[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static void TestSendPictureToMSPaint()
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Clipboard.SetData(System.Windows.Forms.DataFormats.Bitmap, bmp);
//optional#1 - open MSPaint yourself
//var proc = Process.Start("mspaint");
IntPtr msPaint = IntPtr.Zero;
//while (msPaint == IntPtr.Zero) //optional#1 - if opening MSPaint yourself, wait for it to appear
msPaint = FindWindowEx(IntPtr.Zero, new IntPtr(0), "MSPaintApp", null);
SetForegroundWindow(msPaint); //optional#2 - if not opening MSPaint yourself
IntPtr currForeground = IntPtr.Zero;
while (currForeground != msPaint)
{
Thread.Sleep(250); //sleep before get to exit loop and send immediately
currForeground = GetForegroundWindow();
}
SendKeys.SendWait("^v");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)