使用TiffBitmapEncoder和Gray32Float

时间:2014-06-11 12:31:28

标签: c# image image-processing bitmap tiff

我正在尝试使用this code which I found on MSDN

创建32 BPP灰度tiff
BitmapSource image = BitmapSource.Create(
                width,
                height,
                96,
                96,
                PixelFormats.Gray32Float,
                null,
                pixels,
                stride);

FileStream stream = new FileStream("test file.tif", FileMode.Create);

TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.None;
var bitmapFrame = BitmapFrame.Create(image);
encoder.Frames.Add(bitmapFrame);
encoder.Save(stream);

当我打开文件时,文件被创建并且图像看起来正确,但是文件属性表明它是16 BPP(0-65536)图像而不是Gray32Float参数指定的32位浮点图像

通过查看Windows资源管理器中的文件属性并打开ImageJ中的文件

,我确认文件格式为16 BPP

我可以在Paint.Net和ImageJ中创建32个BPP tiff,以确认支持该格式。

任何人都知道为什么.Net TiffBitmapEncoder会创建错误的类型?

1 个答案:

答案 0 :(得分:1)

在幕后,.Net使用Windows Imaging Component(WIC)。 WIC支持在Gray32Float(WIC中的GUID_WICPixelFormat32bppGrayFloat)中读取TIFF,但不写。看看WIC Native Pixel Formats Overview。我有同样的经历,发现图像被写成Gray16。

这非常令人沮丧。我一直在尝试使用Gray32Float写一些科学数据,但我没有成功。