Results 1 to 9 of 9

Thread: Load Image File [Resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Load Image File [Resolved]

    Hi guys good day. I have this problem about loading an image that was saved from the database(convert the image file to byte then saved). When I was going to load it(convert the value to byte then use the memorystream class to convert the byte file to image file) but it throws an exception "Input string was not in a correct format".

    Am I missing something here?

    Here's the code:
    Code:
    private void button1_Click(object sender, System.EventArgs e)
    		{
    			getimage();
    		}
    
    //method to get the binary value in the database
    void getimage()
    		{				
    			cn.Open();
    			SqlCommand cm=new SqlCommand("select * from sample",cn);
    			byte[] img={byte.Parse(cm.ExecuteScalar().ToString())};<---line that throws an error.			
    			cn.Close();			
    			loadimage(img);
    
    		}
    //method to load the image 
    Image ximage;
    		void loadimage(byte[] img)
    		{
    			System.IO.MemoryStream im=new System.IO.MemoryStream(img);			
    			im.Flush();
    			ximage=Image.FromStream(im);
    			im.Close();
    			this.pictureBox1.Image=ximage;
    		}
    Last edited by mar_zim; Jan 29th, 2006 at 11:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width