0

我有 for 循环来保存和保存添加多帧 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));

}

4

0 回答 0