gpt4 book ai didi

c# - TypeConverter 将 byte[] 转换为 Bitmap

转载 作者:行者123 更新时间:2023-11-30 18:38:50 30 4
gpt4 key购买 nike

我有这个:

byte[] ar = new byte[ArrayAnsammlung[DurchLaeufer].Length];
ArrayAnsammlung[DurchLaeufer].CopyTo(ar, 0);
TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
try
{
bild = (Bitmap)tc.ConvertFrom(ar);
}
catch (Exception ddd)
{
Console.WriteLine(ddd.ToString());
}

ar包含位图数据,即Blue-Green-Red-Alpha-Blue....

我正在尝试将其转换为位图图片。这是控制台显示的内容:

A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll
System.ArgumentException: Invalid Parameter.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
at SK.MainWindow.thread() in MainWindow.xaml.cs:Zeile 523.

我该如何解决这个问题?

最佳答案

试试这个:

public static Bitmap BytesToBitmap(byte[] byteArray)
{
using (MemoryStream ms = new MemoryStream(byteArray))
{
Bitmap img = (Bitmap)Image.FromStream(ms);
return img;
}
}

关于c# - TypeConverter 将 byte[] 转换为 Bitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10892131/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com