Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Experts, I am developing a windows application called Barcode Reader and Folder Creator with the use of "OnBarcode.Barcode.BarcodeScanner.dll". I want to read the barcode from the tiff files and create corresponding barcode named folder. In this folder, I want to save the particular image (Barcode Matched page). I have done all the stuff except the Particular age in the folder.

Please help me out.

[Update by OP]
I have done the Barcode reader and folder creation stuff.

But i need help to split and save the tiff image into appropriate folder.

For eg. in the tiff file has 8 pages.

Page 1 has barcode : ABC101
Page 2 no Barcode

Page 3 has barcode: ABC102
Page 4 no Barcode

Page 5 has barcode: ABC103
Page 6 no Barcode

Page 7 has barcode: ABC104
Page 8 no Barcode


output:


Folder Name : ABC101
In this split the page 1 and save into that folder.

Folder Name : ABC102
In this split the page 3 and save into that folder.

and vice versa....

I hope its clear now


Thanks,
Murugavel S
Posted
Updated 8-Mar-13 6:25am
v3
Comments
[no name] 8-Mar-13 11:50am    
And your question is what exactly?
ZurdoDev 8-Mar-13 11:53am    
Can you be more clear on where you are stuck?
Zoltán Zörgő 10-Mar-13 17:12pm    
Any progress?
Murugavel Sadagopan 12-Mar-13 22:17pm    
Hi,

I got the solution.

Thanks,
Murugavel S

1 solution

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.
C#
using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;

namespace MyNetstat
{
	class Program    
	{
		static string ExtractBarcode(BitmapSource frame)
		{
			// here comes your barcode reader
			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);
				}
			}			
		}
	}
}
 
Share this answer
 
v3
Comments
Murugavel Sadagopan 8-Mar-13 21:41pm    
Hi,

is it possible to send the sample code...

Thanks,
Murugavel S
Zoltán Zörgő 9-Mar-13 5:07am    
What for complete code? You want me to do your job? I hope you don't. You have the barcode recognition code, you have the input files. I can only guide you, since your question is not that concrete. So what code do you expect from me?
Murugavel Sadagopan 9-Mar-13 23:17pm    
Also thanks for you prompt response....
Keep it up
Murugavel Sadagopan 9-Mar-13 23:16pm    
Hi
First you read my reply fully ...
I have mentioned sample code not the complete code....

Anyway you leave it....

Thanks,
Murugavel S
Zoltán Zörgő 10-Mar-13 3:27am    
Sorry, you'r right. Still, you have nothing to complain about.
Then again: sample code for what exactly?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900