Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Display image on Bitmap

Display image on Bitmap

Scheduled Pinned Locked Moved C#
csharpgraphics
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    asma_panjabi
    wrote on last edited by
    #1

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

    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

    N A A 4 Replies Last reply
    0
    • A asma_panjabi

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

      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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      How big is the file ?

      asma_panjabi wrote:

      string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);

      getting file name ? Use System.IO.Path.GetFileName()

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      A 1 Reply Last reply
      0
      • N N a v a n e e t h

        How big is the file ?

        asma_panjabi wrote:

        string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);

        getting file name ? Use System.IO.Path.GetFileName()

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        A Offline
        A Offline
        asma_panjabi
        wrote on last edited by
        #3

        It doesnt work for any size of file

        1 Reply Last reply
        0
        • A asma_panjabi

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

          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

          A Offline
          A Offline
          asma_panjabi
          wrote on last edited by
          #4

          sometimes it executes for .jpg but it never takes .gif file. Please some solution for it.

          1 Reply Last reply
          0
          • A asma_panjabi

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

            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

            A Offline
            A Offline
            Anthony Mushrow
            wrote on last edited by
            #5

            asma_panjabi wrote:

            string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1); File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true); string fname = Application.StartupPath + "\\Temp\\" + filename;

            Whats all this part about? Why not just use the path that the OpenFileDialog gets? Also, why do you have a Graphics grphs = CreateGraphics(); it doesn't get used in the code you posted and idealy you shouldn't be using it anyway. If you want to draw to your form you should do it in the OnPaint event. I mean, that Graphics object could be the thing causing your problems, try moving it out of the try block and see what happens.

            My current favourite word is: I'm starting to run out of fav. words!

            -SK Genius

            Game Programming articles start -here[^]-

            A 1 Reply Last reply
            0
            • A Anthony Mushrow

              asma_panjabi wrote:

              string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1); File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true); string fname = Application.StartupPath + "\\Temp\\" + filename;

              Whats all this part about? Why not just use the path that the OpenFileDialog gets? Also, why do you have a Graphics grphs = CreateGraphics(); it doesn't get used in the code you posted and idealy you shouldn't be using it anyway. If you want to draw to your form you should do it in the OnPaint event. I mean, that Graphics object could be the thing causing your problems, try moving it out of the try block and see what happens.

              My current favourite word is: I'm starting to run out of fav. words!

              -SK Genius

              Game Programming articles start -here[^]-

              A Offline
              A Offline
              asma_panjabi
              wrote on last edited by
              #6

              I need to send the image from one user to other so i have to copy the file to my drive. So

              File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
              string fname = Application.StartupPath + "\\Temp\\" + filename;

              I have removed Graphics grphs = CreateGraphics(); from try catch but no gain in that. Plz help

              1 Reply Last reply
              0
              • A asma_panjabi

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

                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

                A Offline
                A Offline
                asma_panjabi
                wrote on last edited by
                #7

                Please itz urgent

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups