Search code examples
c#devexpress

How to get Byte Array from PictureBox?


I'm using DevExpress PictureEdit, I'm trying to get the bytes of the image loaded from the following code

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

but it always returns null. How to do it?


Solution

  • The PictureEdit.EditValue property does not contains byte array at all. This property contains the System.Drawing.Image instance (proof). Thus, to get image bytes from PictureEdit use the following approach:

    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();
    }