简体   繁体   English

将bmp保存到字典c#

[英]Save bmp to dictionary c#

I'm trying to save bmp file to dictionary im using this code 我正在尝试使用此代码将bmp文件保存到字典im

Dictionary<string,MemoryStream> dict = new Dictionary<string,MemoryStream>();

dict.Add("mypicture.png",new MemoryStream());

image.Save(dict["mypicture.png"]);

but for some reason, i have an error in the last sentence i dont know why, is there a missing parameter that i should add in the last function? 但由于某种原因,我在最后一句中有一个错误,我不知道为什么,是否有一个缺少参数,我应该在最后一个函数中添加?

Try this: 尝试这个:

image.Save(dict["mypicture.png"], ImageFormat.Png);

Don't forget include the library 别忘了包括图书馆

using System.Drawing.Imaging;

Here is how you can define your image format: 以下是定义图像格式的方法:

if (ImageFormat.Jpeg.Equals(image.RawFormat))
{
    // JPEG
}
else if (ImageFormat.Png.Equals(image.RawFormat))
{
    // PNG
}
else if (ImageFormat.Bmp.Equals(image.RawFormat))
{
    // BMP
}

So the best solution is 所以最好的解决方案是

 image.Save(dict["mypicture.bmp"], image.RawFormat);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM