2017-04-05 38 views
1

在我的web應用程序中,我使用LeadTools從流中創建多頁Tiff文件。以下是顯示我如何使用leadtools的代碼。LeadTools MaximumGlobalRasterImageMemory

using (RasterCodecs codecs = new RasterCodecs()) 
{ 
    RasterImage ImageToAppened = default(RasterImage); 
    RasterImage imageSrc = default(RasterImage); 
    codecs.Options.Load.AllPages = true; 
    ImageToAppened = codecs.Load(fullInputPath, 1); 
    FileInfo fileInfooutputTiff = new FileInfo(fullOutputPath); 
    if (fileInfooutputTiff.Exists) 
    { 
     imageSrc = codecs.Load(fullOutputPath); 
     imageSrc.AddPage(ImageToAppened); 
     codecs.Save(imageSrc, fullOutputPath, RasterImageFormat.Ccitt, 1); 
    } 
    else 
    { 
     codecs.Save(ImageToAppened, fullOutputPath, RasterImageFormat.Ccitt, 1); 
    } 
} 

上面的代碼工作正常,我在2000年左右的請求中得到了很多對我的web應用程序的請求。在某些情況下,我得到以下錯誤。但後來再次適用於其他請求。

You have exceeded the amount of memory allowed for RasterImage allocations.See RasterDefaults::MemoryThreshold::MaximumGlobalRasterImageMemory. 

是內存問題是單個請求還是所有的對象在應用程序啓動期間(全局對象)? 那麼上述錯誤的解決方案是什麼?

+1

您是否嘗試閱讀[文檔](https://www.leadtools.com/help/leadtools/v19m/dh/l/rastermemorythreshold-maximumglobalrasterimagememory.html)? – Evk

回答

1

在處理多頁文件,這裏有一些一般性的提示,可以幫助Web和桌面應用程序:

  • 避免加載所有頁面,在內存中把它們添加到一個RasterImage。而是循環遍歷它們並一次加載一個(或幾個),然後將它們附加到輸出文件而不將它們保存在內存中。追加到文件可能會隨着頁數的增加而變慢,但this help topic解釋瞭如何加快速度。
  • 您的代碼中有「使用(RasterCodecs編解碼器)」,但大內存用於圖像,而不是編解碼器對象。考慮將RasterImage對象封裝在「使用」範圍中以加快處理速度。換句話說,去「使用(RasterImage圖像= ...)」
  • 而明顯的建議:去64位,儘可能多地安裝RAM,並增加MaximumGlobalRasterImageMemory的值。
3

錯誤您報告引用MaximumGlobalRasterImageMemory

已超出內存允許RasterImage allocations.See RasterDefaults量:: MemoryThreshold :: MaximumGlobalRasterImageMemory。

documentation它指出:

獲取或設置指定允許所有RasterImage對象分配的最大大小的值。

當分配新的RasterImage對象時,如果新分配導致所有分配的RasterImage對象使用的總內存超過MaximumGlobalRasterImageMemory的值,則分配將引發異常。

因此,它看起來像它的所有對象。

這是指定的默認值:

在x86系統上,此屬性默認爲1.5 GB。

在x64系統上,此屬性默認爲1.5 GB或系統總物理RAM的75%,以較大者爲準。

我會建議您熟悉SDK的文檔。

+0

是的。我看過這篇文章。但是這個限制是針對應用程序級別還是單個請求(如果我有大型tiff文件)? – Navaneet

+0

再次閱讀文檔和我的答案 - 它清楚地表明所有分配的RasterImage對象使用的內存總量。 –

+0

好的。我猜RasterImage對象沒有正確處理。所以在使用對象之後調用dispose方法可能會有所幫助。因爲垃圾收集器可能不會自動更快地處理它們在使用rasterimages之後調用dispose方法會有幫助嗎?任何想法。 – Navaneet

相關問題