2015-10-28 8 views
5

हर बार जब मैं अपने SoftwareBitmap को WriteableBitmap में कनवर्ट करना चाहता हूं तो मुझे निम्न अपवाद मिलता है: System.Runtime.InteropServices.COMExceptionसॉफ़्टवेयर बिटमैप को लिखित करने योग्य बिटमैप

private async void Start(object sender, RoutedEventArgs e) 
     { 

      _MediaCapture = new MediaCapture(); 
      await _MediaCapture.InitializeAsync(); 

      mediaElement.Source = _MediaCapture; 
      await _MediaCapture.StartPreviewAsync(); 
      DispatcherTimer timer = new DispatcherTimer(); 
      timer.Interval = new TimeSpan(0, 0, 0, 1); 
      timer.Tick += HandleTimerTick; 
      timer.Start(); 
     } 

     private async void HandleTimerTick(object Sender, object E) 
     { 


      var frame = await _MediaCapture.GetPreviewFrameAsync(); 
      SoftwareBitmap frameBitmap = frame.SoftwareBitmap; 
      WriteableBitmap bitmap = new WriteableBitmap(frameBitmap.PixelWidth, frameBitmap.PixelHeight); 
      try 
      { 
       frameBitmap.CopyToBuffer(bitmap.PixelBuffer); 
      } 
      catch (Exception) 
      { 
       Debug.WriteLine("Exception "); 
      } 
     } 

लाइन

frameBitmap.CopyToBuffer(bitmap.PixelBuffer); 

अपवाद फेंक है:

यहाँ उस के लिए मेरे कोड का टुकड़ा है।

मैं इसे x64 रिमोटडिवाइस पर डिबग कर रहा हूं।

+0

अपवाद क्या फेंक दिया जाता है:

आप के रूप में निम्नलिखित कोड का उपयोग करके इस समस्या को हल कर सकते हैं? –

+0

@Dmitry Bychenko ऊपर देखो: System.Runtime.InteropServices.COMException – TheTanic

+0

साइड नोट: * निगलने * अपवाद जैसे 'पकड़ (अपवाद) {डीबग। राइटलाइन ("अपवाद"); } 'एक * बहुत बुरा अभ्यास * है। –

उत्तर

6

मैं आपके कोड का उपयोग करके इस समस्या को पुन: उत्पन्न कर सकता हूं। यह फ्रेम के कारण होता है। सॉफ्टवेयर बिटमैप हमेशा शून्य देता है।

private async void button_Click(object sender, RoutedEventArgs e) 
    { 
     _mediaCapture = new MediaCapture(); 

     await _mediaCapture.InitializeAsync(); 

     mediaElement.Source = _mediaCapture; 

     await _mediaCapture.StartPreviewAsync(); 

     DispatcherTimer timer = new DispatcherTimer(); 
     timer.Interval = new TimeSpan(0, 0, 0, 1); 
     timer.Tick += Timer_Tick; 
     timer.Start(); 
    } 

    private async void Timer_Tick(object sender, object e) 
    { 
     var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; 

     var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height); 

     var frame = await _mediaCapture.GetPreviewFrameAsync(videoFrame); 

     SoftwareBitmap frameBitmap = frame.SoftwareBitmap; 

     WriteableBitmap bitmap = new WriteableBitmap(frameBitmap.PixelWidth, frameBitmap.PixelHeight); 

     frameBitmap.CopyToBuffer(bitmap.PixelBuffer); 

     Debug.WriteLine("done"); 
    } 
+0

ठीक काम करता है। धन्यवाद – TheTanic

+0

@ जेफरी मुझे समझ में नहीं आता कि यह कैसे मदद करता है ... ऐसा प्रतीत होता है कि केवल वास्तविक अंतर GetPreviewFrameAsync के वापसी मूल्य का उपयोग कर रहा है। यह समझ में नहीं आता है! क्या वह फ़ंक्शन पास करने के लिए पास किए गए वीडियोफ्रेम का उपयोग नहीं करता है? यदि ऐसा है तो इसे अलग-अलग दस्तावेज किया जाना चाहिए। यदि आप वीडियोफ्रेम में InitializeAsync में एक अलग बिटमैप पिक्सेल प्रारूप निर्दिष्ट करते हैं तो क्या आप मुझे यह भी बता सकते हैं कि एक perf हिट है? –

+0

@ जेफरी स्पष्ट होना ... यह काम करता है! मैं बस उलझन में हूँ क्यों। –

संबंधित मुद्दे