不需要的图像在位图到图像的大小调整大小
问题描述:
我正在通过WPF(c#)进行图像处理编程(在emgu cv中)。不需要的图像在位图到图像的大小调整大小
OpenFileDialog d = new OpenFileDialog();
if(d.ShowDialog() == true)
{
Bitmap b = new Bitmap(d.FileName);
img1.Source = Util.Convert(b);
}
我使用的代码下面Bitmap
转换为ImageSource
,反之亦然:在我的应用程序,我使用这些代码打开一个图像
public static Bitmap ImageSourceToBitmap(ImageSource imageSource)
{
BitmapSource bitmapSource = (BitmapSource)imageSource;
MemoryStream mse = new MemoryStream();
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(mse);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(mse);
return bitmap;
}
public static BitmapImage Convert(Bitmap src)
{
MemoryStream ms = new MemoryStream();
((System.Drawing.Bitmap)src).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage image = new BitmapImage();
image.BeginInit();
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.EndInit();
return image;
}
图像的大小将会改变(一个奇怪的现象是发生在我的转换)当我从按钮使用它。按钮的代码事件是:
Image<Gray, byte> im = new Image<Gray, byte>(Util.ImageSourceToBitmap(img1.Source));
im._EqualizeHist();
img1.Source = Util.Convert(im.Bitmap);
我也设置stretch = None
。
是什么问题?
答
你在图像上显示什么?这可能会给你一些调整。我通常使用画布和缩放,以便我的图像始终具有相同的大小。
你对我的转换看起来很奇怪。尝试在这里的方法:Convert Bitmaps
由于BitmapImage是一个BitmapSource的派生,这应该适合你。我怀疑它也会更快。
Doug