我有循环保存和保存添加多帧tiff图像。如果它在页面中找到条形码,它会保存多帧tiff并打开新的。但它浪费了记忆力,需要很长时间。我怎样才能加快这个过程?
for (int i = 1; i < num_pages; i++)
{
progressBar1.Value = i;
myImg.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, i);
using (Bitmap firstImage = new Bitmap(myImg))
{
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
if (ReadBarcode(firstImage))
{
//önceki tifi kapat
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
xBitmap.SaveAdd(encoderParameters);
//yeni tif aç
int_file++;
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
encoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
i++;
myImg.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, i);
xBitmap.Dispose();
xBitmap = null;
GC.Collect();
xBitmap = new Bitmap(myImg);
xBitmap.Save("C:\\taranan\\" + "v" + folderno + "-" + int_file.ToString() + ".TIF", encoderInfo, encoderParameters);
}
else
{
xBitmap.SaveAdd(firstImage, encoderParameters);
}
}
}
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
xBitmap.SaveAdd(encoderParameters);
xBitmap.Dispose();
xBitmap = null;
myImg.Dispose();
GC.Collect();
opened = false;
MessageBox.Show("Dosya sayısı: " + (int_file - Convert.ToInt32(fileno) + 1));
}