locked
Reterive image from Sqlce RRS feed

  • Question

  • Hi.,

                  In my windows mobile 6.0 Pocket PC(C#) application I was stored picture box Jpeg image into sqlce as image Datatype.

                 Now I need to display that image into picture box (C#)
     
                 How can I Achieve this.

    Thanks In Advance,
    Bell
    Monday, August 3, 2009 2:16 PM

Answers

  • Hi Bell,

    Check this code which I already tried:

    private Image getimage()
            {
                string strcmd = "select mimage from movie where mname='" + MOvieCombo.SelectedItem.ToString() + "'";
                 con = new SqlCeConnection(Connectionstring);
                SqlCeCommand cmd = new SqlCeCommand(strcmd, con);
                con.Open();
                byte[] barrImg = (byte[])cmd.ExecuteScalar();
                string strfn = Convert.ToString(DateTime.Now.ToFileTime());
                FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
                fs.Write(barrImg, 0, barrImg.Length);
                fs.Flush();
                fs.Close();
                return ByteArrayToImage(barrImg, barrImg.Length);
            }
    
    
    private Image ByteArrayToImage(byte[] barrImg, int p)
            {
                MemoryStream ms = new MemoryStream(barrImg,0,p);
                Bitmap bm = new Bitmap(ms);
                Image returnImage = Image.FromHbitmap(bm.GetHbitmap());
                ms.Close();
                return returnImage;
                
            }
    
    
    //Finally call this
    pictureBox1.Image = getimage();
    Let me know if you find any problem in this.

    Regards,
    Malleswar
    Monday, August 3, 2009 5:23 PM

All replies

  • Hi,

    The following forum posting should help you :-

    http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/a468e4c5-dd2e-403e-a526-94f424c3bd55

    I think you basically want to convert an image from a byte array like the following :-

    http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=799

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Monday, August 3, 2009 4:18 PM
  • Hi Bell,

    Check this code which I already tried:

    private Image getimage()
            {
                string strcmd = "select mimage from movie where mname='" + MOvieCombo.SelectedItem.ToString() + "'";
                 con = new SqlCeConnection(Connectionstring);
                SqlCeCommand cmd = new SqlCeCommand(strcmd, con);
                con.Open();
                byte[] barrImg = (byte[])cmd.ExecuteScalar();
                string strfn = Convert.ToString(DateTime.Now.ToFileTime());
                FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
                fs.Write(barrImg, 0, barrImg.Length);
                fs.Flush();
                fs.Close();
                return ByteArrayToImage(barrImg, barrImg.Length);
            }
    
    
    private Image ByteArrayToImage(byte[] barrImg, int p)
            {
                MemoryStream ms = new MemoryStream(barrImg,0,p);
                Bitmap bm = new Bitmap(ms);
                Image returnImage = Image.FromHbitmap(bm.GetHbitmap());
                ms.Close();
                return returnImage;
                
            }
    
    
    //Finally call this
    pictureBox1.Image = getimage();
    Let me know if you find any problem in this.

    Regards,
    Malleswar
    Monday, August 3, 2009 5:23 PM
  • Hi..Malle and Paul,


                                Thanks for your kind Information..!



                               Thanks a lot..!
    Thanks in Advance, Bharathi :-)
    Tuesday, August 4, 2009 6:56 AM