Question

I have wrote a code that captures an image and save it in a specific folder.Now i need to access this method through an other thread but i couldn't because i have used get data from clipboard.now i need to re write the code with WM_CAP_SAVEDIB.I have seen this link:How to copy image without using the clipboard? before, but i really confused because i am new in programming.could you please help me to rewrite the code without using clipboard?

here is the method i need to access from other thread:

#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
Was it helpful?

Solution

Here is the solution: I should use Marshal.StringToHGlobalAnsi() to Allocate a managed String and copy all of an unmanaged ANSI string into it. new code is this one:

IntPtr hBmp = Marshal.StringToHGlobalAnsi(FinalPath);
SendMessage(mCapHwnd,WM_CAP_SAVEDIB,0,hBmp.ToInt32());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top