SoFunction
Updated on 2025-03-06

C# Instance method for converting byte streams to pictures


usingSystem;
;
;
;
;
;

{
    classImageToByte
    {
        /// <summary>
/// Convert the picture into byte stream
        /// </summary>
/// <param name="img">Image object to be converted</param>
/// <returns>Byte stream returned after conversion</returns>
        publicstaticbyte[] ImgToByt(Image img)
        {
            MemoryStream ms = newMemoryStream();
            byte[] imagedata = null;
            (ms, );
            imagedata = ();
            returnimagedata;            
        }
        /// <summary>
/// Convert byte stream into pictures
        /// </summary>
/// <param name="byt">Byte Stream to convert</param>
/// <returns>Converted Image object</returns>
        publicstaticImage BytToImg(byte[] byt)
        {
            MemoryStream ms = newMemoryStream(byt);
            Image img = (ms);
            returnimg;
        }
        //
        /// <summary>
/// Return the byte stream of the image according to the image path byte[]
        /// </summary>
/// <param name="imagePath">Picture Path</param>
/// <returns>Returned byte stream</returns>
        privatestaticbyte[] getImageByte(stringimagePath)
        {
            FileStream files = newFileStream(imagePath, );
            byte[] imgByte = newbyte[];
            (imgByte, 0, );
            ();
            returnimgByte;
        }
    }
}