カメラからWPFの画像へのビデオストリームがあります。表示する前に、ピクセルごとに WritableBitMap Image にアクセスしようとしています。テストとして、画像全体を白または黒に設定しようとしています。ただし、どちらの場合も AccessViolationException エラーが発生します。
他の投稿を確認しましたが、このエラーは非常に広く、私のケースに固有のものではないようです。なぜこれが機能しないのかわかりません。
私の場合、ピクセルを操作する最良の方法は何ですか? またはなぜこれが機能しないのですか?どんな助けでも大歓迎です
private async void UpdateMasterCameraPreview(IdsFrame frame)
{
if (masterImage != null)
frame.Image.CopyTo(masterImage);
else
masterImage = frame.Image.ToWriteableBitmap();
//BitmapImage temp = ConvertWriteableBitmapToBitmapImage(masterImage);
WriteableBitmap temp = masterImage;
// Here I get the exception, on every pixel access
for (int y = 0; y < temp.PixelHeight; y++)
for (int x = 0; x < temp.PixelWidth; x++)
temp.SetPixel(x, y, 255);
masterImage = temp;
masterImage.Lock();
masterImage.AddDirtyRect(new Int32Rect(0, 0, masterImage.PixelWidth, masterImage.PixelHeight));
masterImage.Unlock();
if (OnMasterFrameCaptured != null)
OnMasterFrameCaptured(this, new CameraFrameCapturedArgs(CameraType.Master, masterImage));
}