C#改变TIFF光度学解释

时间:2012-10-10 15:31:56

标签: c# tiff aforge

我有以下方法调整图像大小并将新调整大小的图像作为TIFF返回(我使用的是ResorgeBilinear对象来自的AForge库)。

private System.Drawing.Image shrinkImageBilinear(System.Drawing.Image original, float newWidthInches, float newHeightInches)
    {
        float imageProportion = (float)original.Width / (float)original.Height;
        float newWidthPixels = original.HorizontalResolution * newWidthInches;
        float newHeightPixels = newWidthPixels / imageProportion;

        ResizeBilinear filter = new ResizeBilinear((int)newWidthPixels, (int)newHeightPixels);
        Bitmap image = new Bitmap(original);
        image = filter.Apply(image);
        Rectangle imageRect = new Rectangle(0, 0, image.Size.Width, image.Size.Height);
        image = image.Clone(imageRect, PixelFormat.Format1bppIndexed);

        MemoryStream byteStream = new MemoryStream();
        image.SetResolution(200, 200);

        image.Save(byteStream, ImageFormat.Tiff);

        Image returnImage = System.Drawing.Image.FromStream(byteStream);
        return returnImage;
    }

我需要写的规格是TIFF标题中的光度学解释不能利用调色板,因此光度学解释只能是0或1,在这种情况下它是3,因为我使用的是PixelFormat .Format1bppIndexed。我写的规范中的另一个要求是图像必须是1bpp。

所以我的问题是,如何在不利用调色板的情况下创建此图像(从而使光度解释为1或0),保持1bpp,将分辨率保持在200 ppi并将格式保持为TIFF?

1 个答案:

答案 0 :(得分:0)

如果您查看aforge代码本身(下载完整源代码),您将有足够的注释来找到答案。