【发布时间】:2010-11-15 02:38:02
【问题描述】:
目前我正在处理一个超声波扫描项目,该项目显示从探头获取的连续图像,为此我正在编写以下代码。
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 方法本身是否会在每次运行时消耗大量性能,还是只是轮询过于频繁?我很好奇处理这个问题的自定义控件是否是更好的方法(因为它是一个恒定的图像流)。
-
会建议任何客户/第三方控件...或者我们可以流式传输位图图像
标签: c# wpf .net-3.5 image-processing