TIffBitmapDecoder[
^] has a frames property you can use to extract pages. As you said you have the barcode reader code. So yo simply have to parse the frames one by one, and save the frame as individual image in the folder you want based on the code you scan on the frame.
[Update]
See following code. There is a place where you can pit your barcode recognition part in. Please not, that although it is a console application, I am using several WPF tools, thus you will need to reference some WPF related framework assamblies - of course it will work with Windows Forms too.
using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;
namespace MyNetstat
{
class Program
{
static string ExtractBarcode(BitmapSource frame)
{
return DateTime.Now.Ticks.ToString();
}
static void SaveFrame(BitmapFrame frame, string rootFolder, string barcode, int frameNumber)
{
string path = Path.Combine(rootFolder, barcode);
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
PngBitmapEncoder encoder = new PngBitmapEncoder();
FileStream stream = new FileStream(Path.Combine(path, string.Format("p{0:d7}.png", frameNumber)), FileMode.Create);
encoder.Interlace = PngInterlaceOption.On;
encoder.Frames.Add(frame);
encoder.Save(stream);
}
public static void Main()
{
string FileName = @"d:\temp\multipage.tif";
string root = @"d:\temp";
Stream imageStreamSource = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
for(int i=0; i<decoder.Frames.Count; i++)
{
string barcode = ExtractBarcode(decoder.Frames[i]);
if(!string.IsNullOrWhiteSpace(barcode))
{
SaveFrame(decoder.Frames[i], root, barcode, i);
}
}
}
}
}