0

내가 필요한 웹캠 기능을 만들기 위해 http://www.codeproject.com/Articles/285964/WPF-Webcam-Control 에있는 예제를 사용했습니다. 나는 대부분 스냅 샷에 관심이 있으며, 위의 예제에서 아무 문제없이 작동하도록 할 수 있습니다. 내 주요 문제는 미리보기 창을 미리 표시하지 않고도 웹캠에서 스냅 사진을 찍을 수 있기를 원한다는 것입니다. 이미지는 디스플레이 나 아무 것도없이 자동으로 저장됩니다. 다음은 내가 (vb.net에서,하지만 난 C#에서 답변을 상관하지 않습니다)이 무엇 :웹캠에서 표현식 인코더를 사용하여 스냅 샷

Public Shared Function TakeSnapshotReturnBytes(panelHeight As Integer, panelWidth As Integer) As Byte() 
    Dim b() As Byte = Nothing 
    Dim vidDevCol As IEnumerable(Of EncoderDevice) = EncoderDevices.FindDevices(EncoderDeviceType.Video) 
    If vidDevCol IsNot Nothing AndAlso vidDevCol.Count > 0 AndAlso vidDevCol(0) IsNot Nothing Then 
     Dim tmpJob As LiveJob = Nothing 
     Dim lvDevSrc As LiveDeviceSource = Nothing 
     Try 
      tmpJob = New LiveJob 
      Using tmpPanel As New System.Windows.Forms.Panel 
       tmpPanel.Height = panelHeight 
       tmpPanel.Width = panelWidth 

       lvDevSrc = tmpJob.AddDeviceSource(vidDevCol(0), Nothing) 
       lvDevSrc.PreviewWindow = New PreviewWindow(New HandleRef(tmpPanel, tmpPanel.Handle)) 
       tmpJob.ActivateSource(lvDevSrc) 

       Using MS As New IO.MemoryStream() 
        Using bmp As New Bitmap(panelWidth, panelHeight) 
         tmpPanel.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height)) 

         bmp.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg) 
         MS.Position = 0 
         Using br As New IO.BinaryReader(MS) 
          b = br.ReadBytes(CInt(MS.Length)) 
         End Using 
        End Using 
      End Using 
      End Using 
     Finally 
      If lvDevSrc IsNot Nothing Then 
       tmpJob.RemoveDeviceSource(lvDevSrc) 
       lvDevSrc.Dispose() 
      End If 
      If tmpJob IsNot Nothing Then 
       tmpJob.Dispose() 
      End If 
     End Try 
    End If 
    Return b 
End Function 

내가 얻을 모든 다시 생각 회색 창입니다. 내가 'PreviewWindow'개체를 사용해서는 안된다고 생각하지만, 나는 대안을 찾을 수 없습니다. 누구든지이 일을 행운이 있습니까?

+0

혹시 이것을 알아 냈습니까? 나는 같은 문제에 뛰어 들고있다. – Herrozerro

+0

아니요, 죄송합니다. 결국 스냅 샷 멀티미디어를위한 leadtools multimedia (http://www.leadtools.com/sdk/multimedia.htm)를 사용하여 끝을 맺습니다. 아니지만 무료. – Phil

답변

0
은 다음과 같이 코드를 변경

:

tmpJob.ActivateSource(lvDevSrc) 

// This delay let your camera to initialize and ready to capture image. 
// Actualy we should find another safer :) way to do this but just to check if it works! 
System.Threading.Thread.Sleep(5000) 

Using MS As New IO.MemoryStream() 

을 그리고 이것은 당신을 위해 작동하는지 확인합니다. 나는 스냅 샷을 캡처 할 때 웹캠이 초기화되지 않았다고 추측합니다.

+0

불행히도 그렇게하지 않았습니다. 그래도 좋은 생각 이었지만 여전히 빈 출력을 얻었습니다. – Phil