2009-11-23 2 views

답변

0

이것은 상당히 쉽습니다. 이 CodeProject tutorial page에는 원하는 것을 수행하는 데 도움이되는 소스 코드가 있습니다.

기본적으로 Image.GetFrameCount()으로 전화하여 다중 페이지 TIFF의 이미지 수를 알 수 있습니다 (실제로는 여러 페이지 TIFF가 있는지 확인하기 만하면됩니다).

결과 TIFF를 저장하는 방법을 실험해야 할 수도 있습니다. 수동으로 TIFF를 다시 조립해야 할 수도 있고 TIFF를 디스크에 다시 쓰기 전에 직접 이미지를 편집/교체 할 수도 있습니다.

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 Powel 페이지에 좋은 내용이 많이 있습니다.

관련 문제