while retrieving image of image datatype problem

已鎖定 while retrieving image of image datatype problem

  • 2012年3月6日 上午 05:45
     
     

    Hi ,

    I have problem.. while retrieving byte array(image) from database

    Stored image in database as byte array (image datatype) . While retrieving image from database array size reduces and actual image not get. Display image error box

    Please guide me...
    Thank You.


    Leenu Thomas

所有回覆

  • 2012年3月6日 上午 06:15
     
      包含代碼

    Hi guy,

     Storing and reading for Net binary picture has the following ways to do:

    1. Path parameter is a picture : Returns byte[ ] type

    public byte[] GetPictureData(string imagepath)

    { FileStream fs = new FileStream(imagepath, FileMode.Open); byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); return byData; }

    2.Parameter type is an image object, returns the byte [ ] types :              

    public byte[] PhotoImageInsert(System.Drawing.Image imgPhoto) { MemoryStream mstream = new MemoryStream(); imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp); byte[] byData = new Byte[mstream.Length]; mstream.Position = 0; mstream.Read(byData, 0, byData.Length);

    mstream.Close();

    return byData;

    }

      The next step is that you only store this stream into your database via store procedure using Image type.

      Sincerely,

      Jason Wang

     


    orichisonic http://blog.csdn.net/orichisonic If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

  • 2012年3月6日 上午 06:54
     
     

    Hi,

    Thanks for your reply ..

    but i can't store it in any folder and cant use name of the file..

    can you suggest any code that will not use file name ..

    this is my code i used early ..

    FileUploader : fuplPhoto

    imgByte = fuplPhoto.FileBytes;
    image.Src = "data:image/png;base64," + Convert.ToBase64String(imgByte);

    to display image ..

    but getting from database a byte array of smaller size

    can we use file stream or memmory stream with out using file name

    Please guide me...
    Thank You


    Leenu Thomas


    • 已編輯 Leenu 2012年3月6日 上午 06:56
    •  
  • 2012年3月7日 上午 05:59
     
     已答覆

    Hi Leenu,

      Based on your description , a blog article has mentioned your topic as follows:

      http://devio.wordpress.com/2011/01/13/embedding-images-in-html-using-c/  

    http://stackoverflow.com/questions/7390983/convert-from-binarydata-to-image-control-in-asp-net 

      I think you can use the first link to show the photograph,and you can use the second link to convert the photograph into filestream.Consequently, you need to store into to the SQL field which has the BLOB type.

      I hope it will solve your problem.

      Sincerely,

      Jason Wang


    orichisonic http://blog.csdn.net/orichisonic If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".