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. Loading a bitmap into an ImageList

Loading a bitmap into an ImageList

Scheduled Pinned Locked Moved C#
questiongraphicshelplearning
5 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.
  • M Offline
    M Offline
    Mark F
    wrote on last edited by
    #1

    I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.

    Image img = Image.FromFile("jsiml.bmp");
     treeViewImageList.Images.AddStrip(img);
    

    The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark

    L T 2 Replies Last reply
    0
    • M Mark F

      I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.

      Image img = Image.FromFile("jsiml.bmp");
       treeViewImageList.Images.AddStrip(img);
      

      The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, Visual can show you how to do this. Example: add an icon to your app, look at what code gets generated. :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      M 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, Visual can show you how to do this. Example: add an icon to your app, look at what code gets generated. :)

        Luc Pattyn [My Articles] [Forum Guidelines]

        M Offline
        M Offline
        Mark F
        wrote on last edited by
        #3

        I see what you mean. Anyway I used the following which works.

        Image img = (Bitmap)JsLib.Properties.Resources.jsiml;
        treeViewImageList.Images.AddStrip(img);
        

        I also had to change the "Build action" property for the bitmap to "Embedded resource". Mark

        L 1 Reply Last reply
        0
        • M Mark F

          I see what you mean. Anyway I used the following which works.

          Image img = (Bitmap)JsLib.Properties.Resources.jsiml;
          treeViewImageList.Images.AddStrip(img);
          

          I also had to change the "Build action" property for the bitmap to "Embedded resource". Mark

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          That's fine.

          Luc Pattyn [My Articles] [Forum Guidelines]

          1 Reply Last reply
          0
          • M Mark F

            I have a single bitmap image that is comprised of 16 images (like a toolbar bitmap). I use the following to load the image into my imagelist.

            Image img = Image.FromFile("jsiml.bmp");
             treeViewImageList.Images.AddStrip(img);
            

            The problem is that the bitmap file must always be in the application folder. How can I add the bitmap as a resource and load the resource? TIA, Mark

            T Offline
            T Offline
            Thomas Stockwell
            wrote on last edited by
            #5

            To add an image as an embedded resource: 1)RightClick the project or folder in project in the Solution Explorer 2)Select Add an Existing Item 3)Locate the bitmap (I prefer clicking the arrow on the open button to choose the add as link. By doing this the latest bitmap will always be added in the build) 4)RightClick the bitmap in the project 5)In the properties window change the build action or where it says content and in the combo box make the value Embedded Resource To use the bitmap in your code: Bitmap b=new Bitmap(/*stream object*/this.GetType().Assembly.GetManifestResourceStream("{projectname}{.foldername if bitmap is in a folder}.{filename}); or something along those lines.

            Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

            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