我想转换多页的彩色tiff文件一c#CompressionCCITT3tiff。我意识到我需要确保所有像素是1位。我还没有找到一个有益的例子的这个线上。

有帮助吗?

解决方案

检查: http://bobpowell.net/onebit.htm

你需要这个转换为CCITT3和CCITT4不支持色(如果我没有记错的).

其他提示

拉皮条的声明:我的工作 Atalasoft, 公司。净图像软件。

使用 dotImage, 这项任务变得像这样的东西:

FileSystemImageSource source = new FileSystemImageSource("path-to-your-file.tif", true); // true = loop over all frames
// tiff encoder will auto-select an appropriate compression - CCITT4 for 1 bit.
TiffEncoder encoder = new TiffEncoder();
encoder.Append = true;

// DynamicThresholdCommand is very good for documents.  For pictures, use DitherCommand
DynamicThresholdCommand threshold = new DynamicThresholdCommand();

using (FileStream outstm = new FileStream("path-to-output.tif", FileMode.Create)) {
    while (source.HasMoreImages()) {
        AtalaImage image = source.AcquireNext();
        AtalaImage finalImage = image;
        // convert when needed.
        if (image.PixelFormat != PixelFormat.Pixel1bppIndexed) {
            finalImage = threshold.Apply().Image;
        }
        encoder.Save(outstm, finalImage, null);
        if (finalImage != image) {
            finalImage.Dispose();
        }
        source.Release(image);
    }
}

鲍勃*鲍威尔的例子是良好的,因为这是不言而喻,但是它有一些问题,其中最重要的是,它使用一个简单的阈值,这是了不起如果你想要的速度和实际上并不在乎你的输出看起来像或输入域是这样的,真的是很多黑色和白色的已经-只是表示颜色。化是一个棘手的问题。当你的任务是减少可用信息的1/24,如何保持正确的信息,然后扔掉其余是一个挑战。DotImage有六个不同的工具(请参考)为二进制化。SimpleThreshold是桶底,从我的观点。

我建议试验期望的结果首先使用tiff和图像公用事业之前,深入编码。我找到了 贵宾 是一个方便的工具。下一个选项是看到什么文输入的输入可以做的。我已经有良好的结果与自由 LibTiff.NET 使用c#(也见 计算器).我感到非常失望通过GDI tiff的功能,虽然你的里程数可能有所不同(我需要失踪的16位灰度)。你也可以使用 文输入的输入 公用事业(即看看 http://www.libtiff.org/man/tiffcp.1.html)

我看到了上述码,并且它看起来像是转换的每一像素与手册的逻辑。

这将为你工作?

进口的系统。图。摄像

'获得的颜色tif文件

昏暗的bmpColorTIF作为新的位图("C:\color.tif")

'选择一个区域tif(会抓住所有框架)

昏暗的rectColorTIF作为新的矩形(0,0,bmpColorTIF.宽,bmpColorTIF.高度)

'克隆的矩形为1位色tif

昏暗的bmpBlackWhiteTIF作为位=bmpColorTIF.克隆(rectColorTIF,PixelFormat.Format1bppIndexed)

'做你想要什么新的位(优等)

...

注:有一吨的pixelformats选择。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top