不需要创建 tiff 文件,因为我已经有了它。我只是想弄清楚基于目录中文件名的前缀创建文件的算法。
我有一个名为C:\Policy Images
. 在这个文件夹中是图片。图片名称如下:
保单编号/图片名称如下:
AAAAAAA-Pic1
AAAAAAA-Pic2
AAAAAAA-Pic3
ZZZZZZZ-Pic1
ZZZZZZZ-Pic2
FFFFFFF-Pic1
...
创建 tiff 文件时,我需要为每个策略编号创建 1 个 tiff。基于上述,例如,Id 有这个:
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)
下面我的代码的问题是它正在为目录中的所有文件创建一个 tiff,而不是基于策略编号。代码中写着“ foreach (string s in AllFilesInDirectory)
”的部分必须是真的foreach
(策略 1/策略 2/策略 3 中的字符串 s 等)。
我该怎么做呢?我现在正用头撞墙。
这就是我到目前为止所拥有的:
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++;
}