2
4

4 回答 4

6

我写了一些东西来从多页 tiff 文件中提取单页。

// Load as Bitmap
using (Bitmap bmp = new Bitmap(file))
{
    // Get pages in bitmap
    int frames = bmp.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
    bmp.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, tiffpage);
    if (bmp.PixelFormat != PixelFormat.Format1bppIndexed)
    {
        using (Bitmap bmp2 = new Bitmap(bmp.Width, bmp.Height))
        {
            bmp2.Palette = bmp.Palette;
            bmp2.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);
            // create graphics object for new bitmap
            using (Graphics g = Graphics.FromImage(bmp2))
            {
                // copy current page into new bitmap
                g.DrawImageUnscaled(bmp, 0, 0);

                                // do whatever you migth to do
                ...

            }
        }
    }
}

该片段加载 tif 文件并将一页(变量 tiffpage 中的数字)提取到新位图中。这没有索引,可以创建图形对象。

于 2009-08-25T12:36:46.557 回答
1

这是 CodeProject 示例的链接,其中包含将 TIFF 文件转换为普通位图的代码,然后您可以像使用任何其他位图一样使用它:

http://www.codeproject.com/KB/GDI-plus/BitonalImageConverter.aspx

于 2009-08-25T12:14:37.027 回答
1

我曾经写过一个小工具来从 tiff 图像创建加密的 pdf。这是一段从 tiff 图像中获取页面的代码:

var bm= new System.Drawing.Bitmap('tif path');
var total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
for(var x=0;x<total;x++)
{
    bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,x);
    var img=Image.GetInstance(bm,null,false);

    //do what ever you want with img object
}
于 2009-08-25T12:19:44.907 回答
1

错误:无法从具有索引像素格式的图像创建图形对象。

...与它是多页 TIFF 无关。索引图像格式意味着它具有调色板,例如,它是 256 色图像。1 位图像 (B&W) 也算作具有 2 种颜色的调色板。

您不能Graphics对使用调色板的图像执行操作,它们需要先转换为 15 位或更高的颜色深度。

于 2011-08-30T10:04:10.643 回答