tiff切片、合并、转换

2 篇文章 0 订阅

A simple TIFF management class

NotProfessional15 Dec 2004
Using GDI+ to parse TIFF files.
Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click  here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can  update your subscriptions.

Introduction

Compared to legacy GDI, the GDI+ that comes with .NET framework is a lot more powerful. This article describes a very simple class that will be used to parse the multi-page TIFF files. The operations include split, join and convert TIFF compression encoder.

Using the code

For those of you playing with fax or OCR software, you might be bored with the various TIFF encoder formats.EncoderValue provided by GDI+ contains most of the compression encoder information that applies to an image. By default, the images saved with Image.Save() are using the LZW encoder while most of the fax software in the market use CCITT standard. Therefore, you should consider carefully when you are dealing with a TIFF image. Nearly all the methods in the TiffManager provide an encoder parameter to handle the encoding part.

/// <summary>
/// This function will output the image
/// to a TIFF file with specific compression format
/// </summary>
/// <param name="outPutDirectory">
///     The splited images' directory</param>
/// <param name="format">The codec for compressing</param>
/// <returns>splited file name array list</returns>
public ArrayList SplitTiffImage(string outPutDirectory,EncoderValue format)
{
  string fileStartString = outPutDirectory + "\\" + 
                           GetFileNameStartString(_ImageFileName);
  ArrayList splitedFileNames=new ArrayList();
  try
  {
    Guid objGuid=image.FrameDimensionsList[0];
    FrameDimension objDimension=new FrameDimension(objGuid);

    //Saves every frame as a separate file.
    Encoder enc=Encoder.Compression;
    int curFrame=0;
    for (int i=0;i<_PageNumber;i++)
    {
      image.SelectActiveFrame(objDimension,curFrame);
      EncoderParameters ep=new EncoderParameters(1);
      ep.Param[0]=new EncoderParameter(enc,(long)format);
      ImageCodecInfo info=GetEncoderInfo("image/tiff");

      //Save the master bitmap
      string fileName=string.Format("{0}{1}.TIF", 
             fileStartString, i.ToString());
      image.Save(fileName,info,ep);
      splitedFileNames.Add(fileName);
      curFrame++;
    }
  }
  catch (Exception)
  {
    throw;
  }

  return splitedFileNames;
}

The various signatures of the TiffManager are listed below:

public void ConvertTiffFormat(string strNewImageFileName, 
                              EncoderValue compressEncoder);
public Image GetSpecificPage(int pageNumber);
public void JoinTiffImages(string[] imageFiles, string outFile, 
                           EncoderValue compressEncoder);
public void RemoveAPage(int pageNumber, EncoderValue compressEncoder, 
                        string strFileName);
public ArrayList SplitTiffImage(string outPutDirectory, EncoderValue format);

Points of Interest

This is really a simple TIFF handling class. You can dive deeper by implementing resolution conversions etc.



原文:http://www.codeproject.com/Articles/9068/A-simple-TIFF-management-class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值