【发布时间】:2011-01-21 07:41:06
【问题描述】:
我在 wpf 应用程序中有 tiff 图像。首先我使用内存流将图像转换为字节,然后将字节转换为位图图像。我给图像提供了位图图像。我还拍摄了另一张图像并直接给它的源图像路径而不进行转换。我观察到的是转换后图像的质量变低了。为什么会发生?
我的代码如下。 我用了 File.ReadAllBytes("filepath") 将图像转换为字节。
我使用下面的方法从 byte[] 中获取 BitmapSource。然后我将 bitmapsource 分配给图像
public static System.Windows.Media.Imaging.BitmapSource ConvertBytesToBitmapSource(byte[] imageBytes)
{
System.Drawing.Bitmap source = new System.Drawing.Bitmap(ConvertBytesToImage(imageBytes));
IntPtr imagePtr = source.GetHbitmap();
System.Windows.Media.Imaging.BitmapSource bitmapSour = null;
try
{
bitmapSour = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(imagePtr,
IntPtr.Zero, System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
catch (Exception ex)
{
logger.Error("Error in converting bytes to BitmapSource", ex);
throw ex;
}
finally
{
DeleteObject(imagePtr);
}
return bitmapSour;
}
【问题讨论】:
-
这是个好问题。如果没有压缩算法,除了伽玛校正,我看不出它们会如何降低质量。