如何将图像中的图片框从C#中的byte [] [英] How to put image in a picture box from a byte[] in C#

查看:205
本文介绍了如何将图像中的图片框从C#中的byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,其中包含位图格式图像的二进制数据。如何显示它使用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

这篇关于如何将图像中的图片框从C#中的byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆