gpt4 book ai didi

c# - 如何从字节数组创建位图?

转载 作者:IT王子 更新时间:2023-10-29 03:47:13 25 4
gpt4 key购买 nike

我搜索了所有关于字节数组的问题,但总是失败。我从来没有编写过 c# 我是这方面的新手。你能帮我如何从字节数组制作图像文件吗?

这是我的函数,它将字节存储在名为 imageData 的数组中

public void imageReady( byte[] imageData, int fWidth, int fHeight))

最佳答案

您需要将这些字节放入MemoryStream:

Bitmap bmp;
using (var ms = new MemoryStream(imageData))
{
bmp = new Bitmap(ms);
}

使用 Bitmap(Stream stream)构造函数重载。

更新:请记住,根据文档和我一直在阅读的源代码,在这些情况下将抛出 ArgumentException:

stream does not contain image data or is null.
-or-
stream contains a PNG image file with a single dimension greater than 65,535 pixels.

关于c# - 如何从字节数组创建位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555394/

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