如何将图像中的图片框从C#中的byte []如何将、图像、图片、byte

2023-09-03 02:40:29 作者:孤久瘾人i

我有一个字节数组,其中包含位图格式图像的二进制数据。如何显示它使用C#PictureBox控件?

I've a byte array which contains an image binary data in bitmap format. How do I display it using the PictureBox control in C#?

我去通一对夫妇以下但不知道上市的,如果我需要把它发送到一个图片前,否则字节数组到的东西转换岗位。我倒是AP preciate你的帮助。谢谢!

I went thru a couple of posts listed below but not sure if I need to convert the byte array into something else before sending it to a picturebox. I'd appreciate your help. Thanks!

如何把图像从图片框位图 http://stackoverflow.com/questions/2540750/load-picturebox-image-from-memory

How to put image in a picture box from Bitmap http://stackoverflow.com/questions/2540750/load-picturebox-image-from-memory

推荐答案

该函数将字节数组转换为位图可以是用来设置图像的图片框的属性。

This function converts byte array into Bitmap which can be use to set the Image Property of the picturebox.

    public static Bitmap ByteToImage(byte[] blob)
    {
        MemoryStream mStream = new MemoryStream();
        byte[] pData = blob;
        mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
        Bitmap bm = new Bitmap(mStream, false);
        mStream.Dispose();
        return bm;

    }

使用范例:

    pictureBox.Image = ByteToImage(byteArr); // byteArr holds byte array value