2014-05-11 42 views
0

我寫了一個代碼捕獲一個圖像,並將其保存在一個特定的文件夾。現在我需要通過其他線程訪問此方法,但我不能,因爲我已經使用從剪貼板獲取數據。現在我需要重新寫與WM_CAP_SAVEDIB.I的代碼已經看到這個鏈接:How to copy image without using the clipboard?之前,但我真的很困惑,因爲我是編程新手。請你幫我重寫代碼而不使用剪貼板?保存捕獲的圖像,而不使用剪貼板與WM_CAP_SAVEDIB使用C#?

這裏是我需要從其他線程訪問的方法:

#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 
+0

你能幫我在C#中使用WM_CAP_SAVEDIB嗎? – Esay

回答

0

這裏是解決方案: 我應該使用Marshal.StringToHGlobalAnsi()分配託管String,並複製所有非託管ANSI字符串進去。 新代碼是這一個:

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