2014-05-11 3 views
0

이미지를 캡처하고 특정 폴더에 저장하는 코드를 작성했습니다. 이제는 다른 스레드를 통해이 메서드에 액세스해야하지만 클립 보드에서 데이터를 가져 왔기 때문에 사용할 수 없습니다. 다시 작성해야합니다. WM_CAP_SAVEDIB.I가있는 코드는이 링크를 보았습니다 : How to copy image without using the clipboard? 전에,하지만 프로그래밍에 새로운 코드이기 때문에 정말 혼란 스럽습니다. 클립 보드를 사용하지 않고 코드를 다시 작성하는 것을 도와 주시겠습니까? 솔루션 여기C#을 사용하여 WM_CAP_SAVEDIB로 클립 보드를 사용하지 않고 캡처 된 이미지 저장?

#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

됩니다 : 여기

내가 다른 스레드에서 액세스하는 데 필요한 방법이다 내가 관리되지 않는 ANSI 문자열을 모두 관리되는 문자열을 할당하고 복사 Marshal.StringToHGlobalAnsi()를 사용한다 그것으로. 새 코드는 다음과 같습니다.

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