如何将图像转换成字节数组

18 浏览
0 Comments

如何将图像转换成字节数组

这个问题已经在这里有了答案:

将System.Windows.Media.ImageSource转换为ByteArray

将Byte数组转换为图像在WPF中

将Byte数组转换为BitmapImage

有人能建议我如何将图像转换为字节数组,反之亦然吗?

我正在开发一个WPF应用程序,并使用一个流阅读器。

admin 更改状态以发布 2023年5月23日
0
0 Comments

将图像对象转换为byte[],您可以按照以下步骤操作:

public static byte[] converterDemo(Image x)
{
    ImageConverter _imageConverter = new ImageConverter();
    byte[] xByte = (byte[])_imageConverter.ConvertTo(x, typeof(byte[]));
    return xByte;
}

0
0 Comments

将图像转换为字节数组的示例代码

public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
   using (var ms = new MemoryStream())
   {
      imageIn.Save(ms,imageIn.RawFormat);
      return  ms.ToArray();
   }
}

C#图像到字节数组和字节数组到图像转换器类

0