Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate paged tiff file based on file prefixes in a directory using C#
    text
    copied!<p>No need for the tiff file creation as I already have it. I'm just trying to figure out the algorithm to create the files based on pre-fixes of the file names in the directory.</p> <p>I have a folder called <code>C:\Policy Images</code>. in this folder are pictures. the names of the pictures are as follows:</p> <p>Policy Number / Picture Name as such:</p> <pre><code>AAAAAAA-Pic1 AAAAAAA-Pic2 AAAAAAA-Pic3 ZZZZZZZ-Pic1 ZZZZZZZ-Pic2 FFFFFFF-Pic1 ... </code></pre> <p>When creating the tiff files, I need to create 1 tiff per policy number. based on the above, for example, Id have this:</p> <pre><code> AAAAAAA-1 (containing 3 pages in this tiff file) ZZZZZZZ-1 (containing 2 pages in this tiff file) FFFFFFF-1 (containing 1 page in this tiff file) </code></pre> <p>The problem with my code below is that it is creating a tiff for all files in the directory and not based on policy number. the part of the code that says "<code>foreach (string s in AllFilesInDirectory)</code>" needs to be really <code>foreach</code> (string s in policy 1/policy 2/policy 3, etc).</p> <p>how exactly would I do that? im beating my head against a wall right now.</p> <p>this is what I have so far:</p> <pre><code>string[] AllFilesInDirectory = Directory.GetFiles(SelectedDirectory); //get the codec for tiff files ImageCodecInfo info = null; foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders()) if (ice.MimeType == "image/tiff") info = ice; //use the save encoder Encoder enc = Encoder.SaveFlag; EncoderParameters ep = new EncoderParameters(1); ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame); Bitmap pages = null; int frame = 0; foreach (string s in AllFilesInDirectory) { if (frame == 0) { pages = (Bitmap)Image.FromFile(s); //save the first frame pages.Save(AppVars.MergedPolicyImagesFolder + "\\" + PolicyNumber + ".tiff", info, ep); PolicyNumber++; } else { //save the intermediate frames ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage); Bitmap bm = (Bitmap)Image.FromFile(s); pages.SaveAdd(bm, ep); } if (frame == AllFilesInDirectory.Length - 1) { //flush and close. ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush); pages.SaveAdd(ep); } frame++; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload