2017-11-13 19 views
2

私のカメラからのストリームをレンダリングするには、ワーカースレッドを使用しています私のフォーム.INため、メモリ使用量のフレーム私はボタンをクリックしたときに、いくつかの時間のためにvideo.Butにプレートを検出するために、pictureRTSP.BackgroundImageを使用し、ボタンを持っている私は、このエラーを取得:System.AccessViolationException:あなたが見ることができるように.NETランタイムエラーC#のワーカースレッド私は私のWindowsフォームでのPictureBoxを持って

Application: nMCR.exe 
Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception. 
Exception Info: System.AccessViolationException 
    at <Module>.av_read_frame(libffmpeg.AVFormatContext*, libffmpeg.AVPacket*) 
    at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32, System.Drawing.Imaging.BitmapData) 
    at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame() 
    at nMCR.form.MainForm.updateui() 
    at System.Threading.ThreadHelper.ThreadStart_Context(System.Object) 
    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
    at System.Threading.ThreadHelper.ThreadStart() 

マイボタンコード:

BitmapImage bmImage = null;

 if (IsRTSP) 
     { 
      //FinalImage = new Bitmap(_snapshotHandler.TakeSnapshot().ToImage()); 

       FinalImage = new Bitmap(pictureRTSP.BackgroundImage); 



      //Bitmap img = (Bitmap)Image.FromStream(FinalImage); 
      bmImage = new BitmapImage(); 

      using (MemoryStream memStream2 = new MemoryStream()) 
      { 
       FinalImage.Save(memStream2, System.Drawing.Imaging.ImageFormat.Png); 
       memStream2.Position = 0; 

       bmImage.BeginInit(); 
       bmImage.CacheOption = BitmapCacheOption.OnLoad; 
       bmImage.UriSource = null; 
       bmImage.StreamSource = memStream2; 
       bmImage.EndInit(); 
      } 

enter image description here

+0

@Fildorはちょうど私のエラー.Iが望む見ますなぜこのエラーが出るのか知るために? –

+0

@Fildor詳細を教えてください。 –

+0

@Fildorはい正確に.iエラーが発生した行を示す画像を投稿する –

答えて

2

まずあなたがビデオリーダーを開くに問題を抱えている、私はC++のネイティブを使用しているいくつかのライブラリ、それを32ビットを作ってみてください、あなたのソリューションのプラットフォームターゲットに問題があると思います内部のdllは32ビットで、AnyCPUでは動作しません。

第二にあなたがメインスレッド以外のスレッドからpictureboxの背景画像を変更する:

picturebox画像を変更するときに呼び出しを呼び出してみてください。

this.Invoke(new Action(()=> pictureRTSP.BackgroundImage = currentFrame)); 
+0

これは問題でもありますが、Stacktraceからは、その行の前に認識される例外がスローされるようです。 – Fildor

+0

私はそれをテストしようとしています。 –

+0

同じエラーが返されました –

関連する問題