【问题标题】:Saving a captured image without using clipboard with WM_CAP_SAVEDIB using C#?使用 C# 在不使用带有 WM_CAP_SAVEDIB 的剪贴板的情况下保存捕获的图像?
【发布时间】:2014-05-11 07:58:25
【问题描述】:

我已经编写了一个捕获图像并将其保存在特定文件夹中的代码。现在我需要通过其他线程访问此方法,但我不能,因为我已经使用从剪贴板获取数据。现在我需要重新用 WM_CAP_SAVEDIB 写代码。我以前看过这个链接:How to copy image without using the clipboard?,但我真的很困惑,因为我是编程新手。你能帮我在不使用剪贴板的情况下重写代码吗?

这是我需要从其他线程访问的方法:

#region Capture
 public void CaptureFunc()
        {
            PhotoNo = PhotoNo + 1;
            // get the next frame;
            SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);
            // copy the frame to the clipboard
            SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);
            tempObj = Clipboard.GetDataObject();
            tempImg =(System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);
            Graphics graphics = Graphics.FromImage(tempImg);                   
            // Create Directory & Save             
            CreateDir();                   
            tempImg.Save(Path.Combine(Dirname,PhotoNo.ToString()) + ".jpeg", jgpEncoder, myEncoderParameters);  }

#endregion

【问题讨论】:

  • 你能帮我在 C# 中使用 WM_CAP_SAVEDIB 吗?

标签: c# capture autosave


【解决方案1】:

解决方法如下: 我应该使用 Marshal.StringToHGlobalAnsi() 来分配托管字符串并将所有非托管 ANSI 字符串复制到其中。 新代码是这个:

IntPtr hBmp = Marshal.StringToHGlobalAnsi(FinalPath);
SendMessage(mCapHwnd,WM_CAP_SAVEDIB,0,hBmp.ToInt32());

【讨论】:

    猜你喜欢
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多