locked
how to convert the hashtable data into image RRS feed

  • Question

  • User96253324 posted

     Hi,

    I am reading an jpeg file and storing the byte[] values in hashtable , how to fetch the value from the hashtable and disply the image in the web page.

     Thanks,

    Renuga P

    Wednesday, November 26, 2008 6:03 AM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to convert the bytes[] to image, right?

    <o:p> </o:p>

    If so, you may try the following code snippet:

    <o:p> </o:p>

    public static byte[]

    ConvertImageToByteArray(System.Drawing.Image imageToConvert,

    ImageFormat formatOfImage)

    {

    byte[] Ret;

    try

    {

    using (MemoryStream ms = new MemoryStream())

    {

    imageToConvert.Save(ms, formatOfImage);

    Ret = ms.ToArray();

    }

    }

    catch (Exception) { throw; }

    return Ret;

    }

    <o:p> </o:p>

    public static Image ConvertByteArrayToImage(byte[] byteArray)

    {

    if (byteArray != null)

    {

    MemoryStream ms = new MemoryStream(byteArray, 0,

    byteArray.Length);

    ms.Write(byteArray, 0, byteArray.Length);

    return Image.FromStream(ms, true);

    }

    return null;

    }

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 2, 2008 12:57 AM

All replies

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to convert the bytes[] to image, right?

    <o:p> </o:p>

    If so, you may try the following code snippet:

    <o:p> </o:p>

    public static byte[]

    ConvertImageToByteArray(System.Drawing.Image imageToConvert,

    ImageFormat formatOfImage)

    {

    byte[] Ret;

    try

    {

    using (MemoryStream ms = new MemoryStream())

    {

    imageToConvert.Save(ms, formatOfImage);

    Ret = ms.ToArray();

    }

    }

    catch (Exception) { throw; }

    return Ret;

    }

    <o:p> </o:p>

    public static Image ConvertByteArrayToImage(byte[] byteArray)

    {

    if (byteArray != null)

    {

    MemoryStream ms = new MemoryStream(byteArray, 0,

    byteArray.Length);

    ms.Write(byteArray, 0, byteArray.Length);

    return Image.FromStream(ms, true);

    }

    return null;

    }

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 2, 2008 12:57 AM
  • User96253324 posted

     thanks, this helps  me.

    Tuesday, December 2, 2008 4:40 AM