Image
コントロールを含む WPF アプリケーションがあります。を使用WriteableBitmap
して更新してImage.source
いますが、なぜこの奇妙な動作が見られるのか理解できません。画像が 2 つの部分に分かれており、上部がかなり遅い速度で周期的にゆっくりと下部に移動しています。
なぜこれが起こるのか分かりません。上の部分と下の部分は、両方でリアルタイムの更新を確認できるため、実際には同じフレームです。
私のコード:
public MainWindow()
{
InitializeComponent();
InitVideo();
image.Source = frame;
}
private void InitVideo
{
/// .... some other init stuff ...
frame = new WriteableBitmap(width, height, 96, 96, PixelFormats.Rgb24, null);
rgbch = new byte[stride * height];
dataProc = new System.Threading.Thread(ReadData);
dataProc.Start();
}
// in separate thread
private void ReadData()
{
while (rxVideo)
{
for (int i = 0; i < rgbch.Length; i += stride)
{
pipe.Read(rgbch, i, stride);
}
Application.Current.Dispatcher.Invoke(() =>
{
frame.Lock();
frame.WritePixels(new Int32Rect(0, 0, width, height), rgbch, stride, 0);
frame.Unlock();
});
}
私は使用しようとしましたframe.dispatcher.invoke
- >同じ結果。試しMarshal.Copy
た - >同じ結果..