Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to develop a winforms based application. In it, I can load a image format tiff, this image containa multiple pages.
I wrote a simple code to load image in application memory.
Here is my code:
C++
public string[] splitTiffPages(string sourceFile, string targetDirectory)
       {
           string[] returnImages;

           try
           {
               


               Image sourceImage = Bitmap.FromFile(sourceFile);
               Image[] sourceImages = splitTiffPages(sourceImage);

               int pageCount = sourceImages.Length;

               returnImages = new string[pageCount];
               for (int i = 0; i < pageCount; i++)
               {
                   FileInfo fi = new FileInfo(sourceFile);
                   string babyImg = targetDirectory + "\\" + fi.Name.Substring(0, (fi.Name.Length - fi.Extension.Length)) + "_PAGE" + (i + 1).ToString().PadLeft(3, '0') + fi.Extension;
                   sourceImages[i].Save(babyImg);
                   returnImages[i] = babyImg;
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
               returnImages = null;
           }

           return returnImages;
       }

My code throws exceptions:
1. parameter is not valid.
2. out of memory

If I click on my tiff file, it will shows no preview available, I am seeing tiff file only in irfan viewer and fstone viewer these are third party tools.
Note: my tiff file has scanned image with multiple pages

Thanks in advance.
Posted
Updated 11-Oct-10 4:09am
v2
Comments
Toli Cuturicu 11-Oct-10 11:03am    
Which line of code throws the Exceptions?
GaneshGoudd 12-Oct-10 9:12am    
at this point i had exceptions

Image sourceImage = Bitmap.FromFile(sourceFile);

What line is throwing the error? Can you try your code with a single image first?
 
Share this answer
 
This would be helpful to you,

A simple TIFF management class[^]

--
Mark as answer if it helps
 
Share this answer
 

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