當我嘗試使用BinaryFormatter序列化一些圖像時,我將得到一個ExternalException - 在GDI +中發生的一般錯誤。一段時間,我決定創建一個簡單的測試項目,以縮小問題:BinaryFormatter.Serialize(Image) - ExternalException - 在GDI中發生了一般性錯誤+
static void Main(string[] args)
{
string file = @"C:\temp\delme.jpg";
//Image i = new Bitmap(file);
//using(FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
byte[] data = File.ReadAllBytes(file);
using(MemoryStream originalms = new MemoryStream(data))
{
using (Image i = Image.FromStream(originalms))
{
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
// Throws ExternalException on Windows 7, not Windows XP
bf.Serialize(ms, i);
}
}
}
}
對於具體的圖像,我已經試過各種加載圖像的方式,我無法得到它的工作在Windows下7,運行程序作爲管理員。
即使我已經複製了確切的SAM e可執行文件和映像到我的Windows XP VMWare實例中,並且我沒有任何問題。
任何人都有的,爲什麼一些圖像不會在Windows 7下運行的任何想法,但XP下工作?
這裏的圖像之一: http://www.2shared.com/file/7wAXL88i/SO_testimage.html
delme.jpg MD5:3d7e832db108de35400edc28142a8281
請提供有問題的圖像之一(上傳某處並給我們鏈接)。 – 2013-04-10 04:00:15
你好,請你選擇最能滿足你需求的帖子作爲答案嗎? – 2013-04-16 02:10:15