我想保存BMP文件使用此代碼保存BMP到字典C#
Dictionary<string,MemoryStream> dict = new Dictionary<string,MemoryStream>();
dict.Add("mypicture.png",new MemoryStream());
image.Save(dict["mypicture.png"]);
到字典 IM但由於某些原因,我在最後一句 我不出錯知道爲什麼,是有一個缺失的參數,我應該添加在最後一個功能?
我想保存BMP文件使用此代碼保存BMP到字典C#
Dictionary<string,MemoryStream> dict = new Dictionary<string,MemoryStream>();
dict.Add("mypicture.png",new MemoryStream());
image.Save(dict["mypicture.png"]);
到字典 IM但由於某些原因,我在最後一句 我不出錯知道爲什麼,是有一個缺失的參數,我應該添加在最後一個功能?
試試這個:
image.Save(dict["mypicture.png"], ImageFormat.Png);
不要忘記包括圖書館
using System.Drawing.Imaging;
這裏是你如何定義你的圖像格式:
if (ImageFormat.Jpeg.Equals(image.RawFormat))
{
// JPEG
}
else if (ImageFormat.Png.Equals(image.RawFormat))
{
// PNG
}
else if (ImageFormat.Bmp.Equals(image.RawFormat))
{
// BMP
}
所以最好的解決辦法是
image.Save(dict["mypicture.bmp"], image.RawFormat);
什麼是錯誤? – CodingGorilla
你會得到什麼例外? – PhonicUK
因爲你的'dict [「mypicture.png」]不包含'png'圖片。你剛剛創建了空的'MemoryStream'。 –