.Net を使用して、複数ページの tiff ファイルの最初のページを新しい画像に置き換えるにはどうすればよいですか。新しいファイルを作成しないことをお勧めします。
3974 次
2 に答える
1
別のファイルを作成しないとできなかったと思います。
最初にすべての画像を読み取り、置き換えたい画像を置き換え、元のソースを閉じてから、ファイルを新しいマルチページ TIFF に置き換えることができますが、大量のメモリを使用すると思います。一度に画像を読み取り、それを新しいファイルに書き込み、最後のステップとしてファイル名を変更します。
何かのようなもの:
// open a multi page tiff using a Stream
using(Stream stream = // your favorite stream depending if you have in memory or from file.)
{
Bitmap bmp = new Bitmap(imagePath);
int frameCount = bmp.GetFrameCount(FrameDimension.Page);
// for a reference for creating a new multi page tiff see:
// http://www.bobpowell.net/generating_multipage_tiffs.htm
// Here all the stuff of the Encoders, and all that stuff.
EncoderParameters ep = new EncoderParameters(1);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
Image newTiff = theNewFirstImage;
for(int i=0; i<frameCount; i++)
{
if(i==0)
{
// Just save the new image instead of the first one.
newTiff.Save(newFileName, imageCodecInfo, Encoder);
}
else
{
Bitmap newPage = bmp.SelectActiveFrame(FrameDimension.Page);
newTiff.SaveAdd(newPage, ep);
}
}
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
newTiff.SaveAdd(ep);
}
// close all files and Streams and the do original file delete, and newFile change name...
それが役に立てば幸い。.NET イメージングに関する質問については、Bob Powellページに多くの優れた情報があります。
于 2009-11-23T19:41:19.723 に答える
0
これはかなり簡単です。このCodeProject チュートリアル ページには、必要なことを行うのに役立つソース コードがあります。
基本的に、複数ページの TIFF 内の画像の数を取得するImage.GetFrameCount()を呼び出す必要があります(実際に複数ページの TIFF があることを確認するためだけです)。
結果の TIFF を保存する方法を試す必要がある場合があります。TIFF を手動で再構築する必要がある場合や、TIFF をディスクに書き戻す前に画像を直接編集/置換できる場合があります。
于 2009-11-23T19:12:24.353 に答える