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:
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?
– Leandro Angelo
@Leandroangelo I identified the line, is where I do "image2.Selectactiveframe()".
– Sofia Rodrigues