2012-04-30 33 views
1

我有兩個tiff圖像,一個是黑白圖像,另一個是灰度圖。C# - 圖像無法在Windows XP中打開,但在Windows 7中運行的代碼相同

我需要向他們展示的圖片中,當我嘗試打開它們:

Image.FromFile("path"); 

的BW一個沒有問題打開,灰階一個給我一個例外:「內存不足」

只有當我在WinXP SP3機器上執行代碼時,有Windows 7的同事在這兩種情況下都沒有問題

任何想法?

更多信息:MS塗料及標準的Microsoft圖像瀏覽器無法打開灰度圖像,而Office圖片管理器可以

的Windows 7可以與任何softwate

我有這個時間的解決方案打開圖像,但我認爲不是最好的:

System.Windows.Media.Imaging.BitmapImage bImg = null; 

using (var fs = new FileStream(dlg.FileName, FileMode.Open)) 
{ 
    bImg = new System.Windows.Media.Imaging.BitmapImage(); 
    bImg.BeginInit(); 
    bImg.StreamSource = fs; 
    bImg.EndInit(); 
} 

if (bImg.Format == System.Windows.Media.PixelFormats.Gray8) 
{ 
    Bitmap bitmap; 

    using (MemoryStream outStream = new MemoryStream()) 
    { 
     BitmapEncoder enc = new BmpBitmapEncoder(); 
     enc.Frames.Add(BitmapFrame.Create(bImg)); 
     enc.Save(outStream); 
     bitmap = new System.Drawing.Bitmap(outStream); 
    } 
    AssignImage(bitmap); 
} 
else 
    AssignImage(Image.FromFile(dlg.FileName)); 

回答

2

Image.FromFile使用本地GDI調用來加載圖像。

當加載不支持的TIFF文件時,有相當多的內存不足異常報告。

http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/582c0a29-97ef-4136-8a7f-81eb1b1f1c94/

http://www.pcreview.co.uk/forums/opening-tiff-file-throws-out-memory-exception-t3105542.html

TIFF文件格式並沒有所有這些都是由Windows天真地支持多種編碼選項。 TIFF文件有點像AVI文件,因爲可以用不同的方式壓縮內容。支持其他格式可能已添加到Windows 7.

是否可以更改您的TIFF文件上的編碼選項?

相關問題