Trying to improve multi-page TIFF file splitting
I am trying to improve the speed at which I am able to split a multi-page
TIFF file into it's individual pages, stored as a list of byte arrays. I
have this TiffSplitter class that I'm working on, to try and improve the
speed of the Paginate method.
I have heard of LibTiff.net, and wonder if it would be any faster than
this process? Currently, it takes about 1333 ms to call the Paginate
method on a 7-page multipage TIFF file.
Does anyone know what would be the most efficient way to retrieve the
individual pages of a multipage TIFF as byte arrays? Or possibly have any
suggestions as to how I can improve the speed of the process I'm currently
using?
TiffSplitter
using System; using System.Collections.Generic; using System.Linq; using
System.Drawing; using System.Drawing.Imaging; using System.IO;
namespace TiffSplitter
{
public class TiffPaginator
{
private List<byte[]> paginatedData;
public List<byte[]> Pages
{
get
{
return paginatedData;
}
}
public TiffPaginator()
{
paginatedData = new List<byte[]>();
}
public void Paginate(string Filename)
{
using (Image img = Image.FromFile(Filename))
{
paginatedData.Clear();
int frameCount = img.GetFrameCount(FrameDimension.Page);
for (int i = 0; i < frameCount; i++)
{
img.SelectActiveFrame(new
FrameDimension(img.FrameDimensionsList[0]), i);
using (MemoryStream memstr = new MemoryStream())
{
img.Save(memstr, ImageFormat.Tiff);
paginatedData.Add(memstr.ToArray());
}
}
}
}
}
}
No comments:
Post a Comment