How to convert Binarydata to Image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mshiva
    New Member
    • Feb 2007
    • 8

    How to convert Binarydata to Image

    hi friends i was new to this forums .in my one of the application i am retriving binarydata from database.

    How should i convert this binary data to imageformat..pl z help me
    my binarydata is:



    Report abuse
    Last edited by kenobewan; Feb 5 '07, 01:06 PM. Reason: Unnecessary binary data removed
  • Sandeep akhare
    New Member
    • May 2006
    • 29

    #2
    Why are you posting Binary data No need of poasting banary data
    ok you can do that use fallowing code to make it
    if i am getting images from database which is in Binary
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
    Byte[] imageData = (byte[])dr[0];
    string FilaName = dr[1].ToString();
    using (MemoryStream ms = new MemoryStream(im ageData, 0, imageData.Lengt h))
    {

    ms.Write(imageD ata, 0, imageData.Lengt h);

    // newImage = Image.FromStrea m(ms, true);
    Bitmap bm = new Bitmap(new MemoryStream(im ageData));
    newImage = bm;
    newImage.Save(p ath + "\\" + FilaName);

    }

    }

    Comment

    • mshiva
      New Member
      • Feb 2007
      • 8

      #3
      Thank u sandeep

      Comment

      • mshiva
        New Member
        • Feb 2007
        • 8

        #4
        hai sandeep with u r code i am getting error in the following line:

        Bitmap bm = new Bitmap(new MemoryStream(im ageData));

        just i changed code acc to my project:

        foreach (DataRow dr in ds.Tables["Photograph "].Rows)
        {
        byte[] imageData = Convert.FromBas e64String(dr["Photograph_Tex t"].ToString());
        string FileName = dr[2].ToString();
        using (MemoryStream mst = new MemoryStream(im ageData, 0, imageData.Lengt h))
        {

        Bitmap bmp = new Bitmap(mst);
        NewImage =bmp;
        NewImage.Save(p ath + "\\" + FileName);
        }

        Comment

        • mshiva
          New Member
          • Feb 2007
          • 8

          #5
          sorry to inform u about the error:

          Parameter is not valid

          Comment

          Working...