Display image on Bitmap

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmapanjabi
    New Member
    • Jan 2008
    • 10

    Display image on Bitmap

    i am trying to pick a image file from open dialog box and send to other user in C#.net

    Code:
    private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.RestoreDirectory = true;
    openFileDialog1.FileName = "";
    openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
    "JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
    File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
    string fname = Application.StartupPath + "\\Temp\\" + filename;
    if(File.Exists(fname))
    WhiteBoard1.iSelected = fname;
    
    FileInfo info = new FileInfo(WhiteBoard1.iSelected);
    long filesize = info.Length;
    if(filesize>0)
    {
    
    WhiteBoard1.strConfid = strConfid;
    WhiteBoard1.LoadImage();
    }
    }
    
    In whiteboard class
    
    public void LoadImage()
    {
    try
    {
    Graphics grphs = CreateGraphics();
    
    if(File.Exists(iSelected))
    {
    Image img1 = Image.FromFile(iSelected);
    pict.Image=img1;
    }
    }
    catch(OutOfMemoryException)
    {
    
    MessageBox.Show(msg.ToString());
    
    }
    }
    I get exception as

    OutofMemory Exception
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Your picture is too big? You don't have enough memory?

    Comment

    • balame2004
      New Member
      • Mar 2008
      • 142

      #3
      You should know your picture size in pixels. Only limited size of picture can be shown.

      Comment

      • asmapanjabi
        New Member
        • Jan 2008
        • 10

        #4
        Originally posted by Plater
        Your picture is too big? You don't have enough memory?
        My image size doesnt matter it doesnt work for 1kb or for more than that.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by asmapanjabi
          My image size doesnt matter it doesnt work for 1kb or for more than that.
          then I would say you have a recursive loop somewhere.
          Set a breakpoint and follow the code flow. You will probably see that it is looping somewhere.
          You are also not disposing of your image objects, that needs to be done.

          Comment

          Working...