Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#中将system.Drawing.Image序列化为流?_C#_Image_Serialization - Fatal编程技术网

如何在c#中将system.Drawing.Image序列化为流?

如何在c#中将system.Drawing.Image序列化为流?,c#,image,serialization,C#,Image,Serialization,我有一个图像对象img,我需要将它保存到内存流中 保存方法具有以下签名: 保存(流、ImageCodeInfo、编码器参数) 但我不知道我应该在参数2和3中提供什么 我使用BinaryFormmater序列化解决了这个问题,但我希望使用最合适的方法 谢谢你的帮助 有您需要的信息。在该页面上,他们将此列为获取ImageCodecInfo的最简单方法: public static ImageCodecInfo FindEncoder(ImageFormat format) { if (fo

我有一个图像对象img,我需要将它保存到内存流中

保存方法具有以下签名:

保存(流、ImageCodeInfo、编码器参数)

但我不知道我应该在参数2和3中提供什么

我使用BinaryFormmater序列化解决了这个问题,但我希望使用最合适的方法

谢谢你的帮助

有您需要的信息。在该页面上,他们将此列为获取ImageCodecInfo的最简单方法:

public static ImageCodecInfo FindEncoder(ImageFormat format) { 
    if (format == null)
        throw new ArgumentNullException("format");

    foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders()) {
        if (codec.FormatID.Equals(format.Guid)) {
            return codec;
        }
    }

    return null;
}
有你需要的信息。在该页面上,他们将此列为获取ImageCodecInfo的最简单方法:

public static ImageCodecInfo FindEncoder(ImageFormat format) { 
    if (format == null)
        throw new ArgumentNullException("format");

    foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders()) {
        if (codec.FormatID.Equals(format.Guid)) {
            return codec;
        }
    }

    return null;
}

有一个更简单的重载:。第二个参数用于选择要保存图像的格式,如BMP、PNG或JPEG

image.Save(stream, ImageFormat.Bmp); // if you need to access the pixels, perhaps
image.Save(stream, ImageFormat.Png); // lossless compression (good for drawings)
image.Save(stream, ImageFormat.Jpeg); // lossy but powerful compression (good for photos)

有一个更简单的重载:。第二个参数用于选择要保存图像的格式,如BMP、PNG或JPEG

image.Save(stream, ImageFormat.Bmp); // if you need to access the pixels, perhaps
image.Save(stream, ImageFormat.Png); // lossless compression (good for drawings)
image.Save(stream, ImageFormat.Jpeg); // lossy but powerful compression (good for photos)

使用并仅指定?使用并仅指定?是的,我看到了此重载,但我不知道要提供哪个参数..:(@stefano:这取决于你想对序列化图像做什么。在不知道的情况下,我们无法告诉你更多。thx很多!这是我需要的!我想(错了)我无法以Bmp格式保存.jpg文件,因此,我不清楚参数的含义..现在一切都清楚了!是的,我看到了此重载,但我不知道要提供哪个参数..:(@stefano:这取决于你想对序列化图像做什么。在不知道的情况下,我们无法告诉你更多。thx太多了!这是我需要的!我(错误地)认为我无法以Bmp格式保存.jpg文件,因此,我不清楚参数的含义……现在一切都清楚了!