2014-02-14 58 views
0

我使用的DevExpress PictureEdit,我想从下面的代码如何从PictureBox获取字节数组?

byte[] picBytes = picStudent.EditValue as byte[]; 

加载的图像的字节,但它总是返回null。怎么做?

+0

你序列化和反序列化picStudent发送作为一个byte []? – 173901

+1

你是什么意思?我只是拖动了PictureEditControl和一个按钮。在该按钮上,我编写了该代码并尝试获取该图片框中的图像字节。 – AndroidLearner

+0

我不确定DevExpress。但是在VS中,当你有图片时,默认情况下它不会被存储为字节[]。您需要将其序列化为一个字节[],然后将其反序列化以检索它。 – 173901

回答

0

PictureEdit.EditValue属性根本不包含字节数组。该属性包含System.Drawing.Image实例(proof)。因此,为了得到PictureEdit图像字节用下面的办法:

Image img = pictureEdit1.EditValue as Image; // or use the PictureEdit.Image property 
using(MemoryStream ms = new MemoryStream()) { 
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); 
    byte[] bytes = ms.ToArray(); 
} 
相关问题