2014-08-28 2 views
1

하나의 다중 페이지 이미지 abc.tiff을 가지고 있습니다. 각 페이지마다 그림을 그려야하고 하나의 다중 페이지 이미지를 일부 D:\xyz 위치에 저장해야합니다.이미지 목록에서 여러 페이지 이미지를 만들 수있는 방법

나는 그것을 위해 코드 아래 사용하고 있습니다 : 나는 D:\xyz 위치에 내 수정 다중 이미지를 저장할 그 후

List<Image> images = new List<Image>(); 
    Bitmap bitmap = (Bitmap)Image.FromFile(@"abc.tiff"); 
    int count = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); 

    for (int idx = 0; idx < count ; idx++) 
    { 

     bitmap.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, idx); 
     // save each frame to a bytestream 
     MemoryStream byteStream = new MemoryStream(); 
     // below 3 lines for drawing something on image... 
     Bitmap tmp = new Bitmap(bitmap, bitmap.Width, bitmap.Height); 
     Graphics g = Graphics.FromImage(tmp); 
     g.DrawRectangle(blackPen, x, y, width, height); 

     tmp.Save(byteStream, System.Drawing.Imaging.ImageFormat.Tiff); 
     tmp.Dispose(); 
     // and finally adding each frame into image list  
     images.Add(Image.FromStream(byteStream)); 
    } 

합니다.

List<Image> 개의 이미지에서 하나의 다중 이미지를 얻으려면 어떻게합니까?

+0

문제를 해결 했습니까? – TaW

답변

1

Bob Powell에서 거의 직접 가져온 것입니다

목록은이 작업을 수행 할 수 있습니다 가득

string saveName = "c:\\myMultiPage.tiff" // your target path 
List<Image> imgList = new List<Image>();  // your list of images 

가정 :

using System.Drawing.Imaging; 
// .. 

System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag; 

// create one master bitmap from the first image 
Bitmap master = new Bitmap(imgList[0]); 
ImageCodecInfo info = null; 

// lets hope we find a tiff encoder! 
foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders()) 
    if (ice.MimeType == "image/tiff") info = ice; 

// we'll always need only one parameter 
EncoderParameters ep = new EncoderParameters(1); 
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame); 

// save the master with our parameter, announcing it will be 'MultiFrame' 
master.Save(saveName, info, ep); 

// now change the parameter to 'FramePage'.. 
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage); 

// ..and add-save the other images into the master file 
for (int i = 1; i < imgList.Count; i++) 
    master.SaveAdd(imgList[i], ep); 

// finally set the parameter to 'Flush' and do it.. 
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush); 
master.SaveAdd(ep); 

밥 파월에 대한 모든 칭찬을!