使用JPEG压缩保存Tiff图像文件很耗时

问题描述 投票:0回答:1

我正在使用Aspose.Imaging 19.11.0.0通过压缩JPEG处理Tiff图像,但是在这里,如果我有10MB +大小的tiff文件(具有50页),那么在这种情况下,旋转所有这些tiff页需要30到40分钟,应用程序将进入无响应模式。在我的代码中,假设我在Tiff图像文件中有50页,然后从客户端应用程序通过foreach循环迭代每个页面,并在服务器端为每个页面发送相应的rotate方法进行旋转,我知道浪费时间的因素之一是发送每个页面而不是一次发送所有页面,但是当我调试代码时,发现tiffImage.Save(Stream, tiffOptions)每页花费的时间也更多。

下面是使用JPEG压缩旋转页面的服务器端代码,在此RotatePageUsingAspose()方法下面的所有页面每次都会被调用,意味着假设我只从50个页面中选择了第3页,那么使用参数pageNumber =3rotation degree = 90 degree的所选页面仅被调用一次在这种情况下,意味着旋转第三页并保存该页面也将花费将近1分钟,这太慢了。

服务器端旋转代码:

private void RotatePageUsingAspose(int pageNo, RotationDegrees rotationDegree)
  {
     float angleOfRotation = (float)rotationDegree;

     // Auto mode is flexible and efficient.
     Cache.CacheType = CacheType.Auto;

     // The default cache max value is 0, which means that there is no upper limit.
     Cache.MaxDiskSpaceForCache = 1073741824; // 1 gigabyte
     Cache.MaxMemoryForCache = 1073741824; // 1 gigabyte

     // Changing the following property will greatly affect performance.
     Cache.ExactReallocateOnly = false;

     TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb);

     //Set RGB color mode.
     tiffOptions.Photometric = TiffPhotometrics.Rgb;
     tiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
     try
     {
        using (TiffImage tiffImage = (TiffImage)Image.Load(Stream))
        {
           TiffFrame selectedFrame = tiffImage.Frames[pageNo - 1];
           selectedFrame.Rotate(angleOfRotation);
           tiffImage.Save(Stream, tiffOptions);
        }
     }
     finally
     {
        tiffOptions.Dispose();
     }
  }

我向Aspose.Imaging团队提出了同样的问题,但他们尚未为此提供解决方案。

请建议对上述代码进行改进,以有效地保存页面。如果可能,请提供实现此目标的方法。

c# image-processing tiff aspose libtiff.net
1个回答
0
投票

@@ Ankit Raman,

我已遵守您的要求。您能否与您一起面对问题的源文件以及有效的示例代码一起共享,以便我们可以对此进行调查,并在可能与性能相关的问题上对API进行可能的改进。请分享所需的信息,以便我们可以进一步为您提供帮助。

我在Aspose担任支持开发人员/宣传人员。

© www.soinside.com 2019 - 2024. All rights reserved.