4
目前,我正在研究一個超聲波掃描項目,該項目顯示從探頭獲取的連續圖像,以此來編寫以下代碼。在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;
}
這種方法花費我大量的(性能), 有沒有更好的辦法這樣做?
轉換方法本身是否在每次運行中花費很多性能,還是僅僅被頻繁查詢?我很好奇,如果一個自定義控件處理這將是更好的方法(因爲它是一個恆定的圖像流)。 – 2009-07-29 15:24:59
會建議任何custome/thirdparty控件...或者我們可以流化位圖圖像 – 2009-07-30 04:19:54