如何发送要在 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");
}
关于vb.net - 将 PictureBox 内容发送到 MsPaint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16072215/