Error in GDI+ when selecting active frame

Asked

Viewed 26 times

1

I have a problem when I try to split multi-page TIFF files.

As I divide the files, I save each page in a temporary folder and save a JPG from that TIFF to use it as a thumbnail of the image in ListView. That is, I save each TIFF page in the temporary folder, for each page in this folder I will save the thumbnail in a folder called "Thumbnails" and present everything in Listview.

My problem is that when I divide the TIFF, the first page works well and when you make the second page, you make this mistake:

Erro

My code is this one:

string pastapdf = AppDomain.CurrentDomain.BaseDirectory + "temporario\\" + name;
Directory.CreateDirectory(pastapdf);

for (int index = 0; index < pages; index++) //aqui funciona tudo bem
{
    activePage = index + 1;                           
    image.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, index);
    image.Save(pastapdf + "\\" + name + " -Pagina " + activePage + ".tif", System.Drawing.Imaging.ImageFormat.Tiff);
}

string[] tiffiles = GetFiles(pastapdf, "*.tif"); //vou buscar os ficheiros TIFF
for(int idx = 0; idx < tiffiles.Length; idx++)
{
    activePage = idx + 1;
    using (System.Drawing.Image image2 = System.Drawing.Image.FromFile(tiffiles[idx]))
    {

        image2.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, idx);//<-- erro aqui 
        image2.Save(thumbnail + "\\" + name + " -Pagina " + activePage + "_thumbnail" + ".jpg", ImageFormat.Jpeg); 
        thumbnails.Images.Add(h.ToString(), image2);
        image2.Dispose();
    }

    string fich = pastapdf + "\\" + name + " -Pagina " + activePage + ".tif";
    //aqui crio o item novo no ListView
    FileInfo f = new FileInfo(fich);
    ListViewItem _item1 = new ListViewItem();
    _item1.ImageKey = h.ToString();
    _item1.Text = name + " -Pagina " + activePage + ".tif";
    _item1.SubItems.Add(f.Length.ToString());

    lista4.Items.Add(_item1);
    h++;
}
  • Where, in the code, the error breaks?

  • @Leandroangelo I identified the line, is where I do "image2.Selectactiveframe()".

1 answer

0


I already solved the problem and it was my mistake.

Since I had already separated the TIFF file before and was only going to fetch pages 1 to 1, I could not select any Activeframe because the pages were already separated and each one had only 1 frame.

In conclusion, just remove the line:

image2.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, idx);

And everything works properly without errors, and the files have been separated before!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.