以下を使用して、ネットワークストリームから受信したバイト配列データを画像に変換して画面に表示しますが、しばらくすると正常に実行された後、「この操作を完了するのに適したイメージングコンポーネントが見つかりませんでした」という例外が発生し続けます。「コンポーネントが見つかりません。(HRESULT からの例外: 0x88982F50)」という内部例外があります。バッファサイズの問題を見てきましたが、それだけではないと思います。何かご意見は?
public static ImageSource ByteToImage(byte[] imageData)
{
BitmapImage biImg = new BitmapImage();
MemoryStream ms = new MemoryStream(imageData);
try
{
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.EndInit();
}
catch ( Exception e)
{
MessageBox.Show("1"+ e.InnerException);
}
ImageSource imgSrc = biImg as ImageSource;
return imgSrc;
}
追加情報
これは、ネットワーク ストリームを受信している HandlerThread で使用しているものです。
NetworkStream networkStream = new NetworkStream(handlerSocket);
int thisRead = 0;
int blockSize = 256000;
Byte[] dataByte = new Byte[blockSize];
lock (this)
{
while (running)
{
thisRead = networkStream.Read(dataByte, 0, blockSize);
Dispatcher.BeginInvoke(new ThreadStart(delegate
{ pictureBox1.Source = ByteToImage(dataByte); }));
if (thisRead == 0) break;
}
}