Load jpg in C# Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darwinrockantansky
    New Member
    • Apr 2010
    • 2

    Load jpg in C# Form

    In a C# (.NET) application, I need to load an image (fixed path) at application start-up.

    Can anyone point me to a working example?

    Thanks
  • Janch
    New Member
    • Apr 2010
    • 1

    #2
    Why not use the form_load event:


    private void Form1_Load(obje ct sender, EventArgs e)
    {
    pictureBox1.Ima ge = Image.FromFile( @"C:\Users\Publ ic\Pictures\Sam ple Pictures\Koala. jpg");
    pictureBox1.Siz eMode = PictureBoxSizeM ode.Zoom;
    }

    Comment

    • darwinrockantansky
      New Member
      • Apr 2010
      • 2

      #3
      Load JPG

      Thanks Janch.

      I used the same solution in-line vs. event driven and it works exactly as I had hoped it would.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Hopefully it's not too late, but be careful doing this. When you load an image from a file this way, it leaves an open handle to the image in question (so it can't be renamed, deleted, moved, etc...).

        If this isn't an issue for you then you're set, but if it could be (and sometimes it's good to err on the side of caution), you can load it into memory and then load the image from the in-memory copy of the image, closing the file handle to the file itself.

        Comment

        Working...