現在、私は次のコードを書いていることを確認するために、プローブから取得した画像を表示する超音波スキャンプロジェクトに取り組んでいます。WPFで画像を表示する最良の方法
XAML:
<Image Name="imgScan" DataContext="{Binding}" Source="{Binding Path=prescanImage,Converter={StaticResource imgConverter}}" />
C#の割り当て:
Bitmap myImage = GetMeImage();
imageMem = new MemoryStream();
myImage .Save(imageMem, ImageFormat.Png);
imgScan.DataContext = new { prescanImage = imageMem.ToArray() };
コンバータ:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is byte[])
{
byte[] ByteArray = value as byte[];
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = new MemoryStream(ByteArray);
bmp.EndInit();
return bmp;
}
return null;
}
この方法は私に(パフォーマンス)の多くは、 原価計算されるに任意のより良い方法はありそれを行う??
Convertメソッド自体は、実行ごとに多くのパフォーマンスを必要としますか、あまりにも頻繁にポーリングされていますか?私はこれを処理するためのカスタムコントロールがより良いアプローチ(画像の一定のストリームなので)になるかどうか不思議です。 –
custome/thirdpartyコントロールを提案するか、ビットマップイメージをストリームすることができます –