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. Displaying multiple images in a picture box

Displaying multiple images in a picture box

Scheduled Pinned Locked Moved C#
question
6 Posts 4 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.
  • O Offline
    O Offline
    Ofori Boadu
    wrote on last edited by
    #1

    I am trying to display multiple images in a single picture box control. Any ideas?

    a novice

    C A L 3 Replies Last reply
    0
    • O Ofori Boadu

      I am trying to display multiple images in a single picture box control. Any ideas?

      a novice

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Your picture box has an image associated with it. The image can be anything including one created in memory. Create a Bitmap (which is a type of image) in memory and draw the multiple other images into it in the appropriate place with the appropriate size.


      Upcoming FREE developer events: * Developer! Developer! Developer! 6 * Developer Day Scotland My website

      1 Reply Last reply
      0
      • O Ofori Boadu

        I am trying to display multiple images in a single picture box control. Any ideas?

        a novice

        A Offline
        A Offline
        Ajay k_Singh
        wrote on last edited by
        #3

        If you are going to show more than one images on a single picture box, you may try creating a new image containing all images which you want to show. Following code will show two images img1.jpg and img2.jpg on the same picture box, by drawing them on a third image; second image will be drawn at the bottom of the first image- -----------------------------Start Code----------------------------- System.Drawing.Bitmap MergedImage; System.Drawing.Image Image1 = Image.FromFile("C:\\img1.jpg"); System.Drawing.Image Image2 = Image.FromFile("C:\\img2.jpg"); if (Image1.Width > Image2.Width) { MergedImage = new Bitmap(Image1.Width, Image1.Height + Image2.Height); } else { MergedImage=new Bitmap(Image2.Width,Image1.Height + Image2.Height); } Graphics g = Graphics.FromImage(MergedImage); g.DrawImage(Image1, 0, 0); g.DrawImage(Image2, 0, Image1.Height); this.pictureBox1.Image = MergedImage; g.Dispose(); --------------------------------------End Code------------------------------- I hope this helps:). -Dave.

        Dave Traister, ComponentOne LLC. www.componentone.com

        O 2 Replies Last reply
        0
        • O Ofori Boadu

          I am trying to display multiple images in a single picture box control. Any ideas?

          a novice

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

          Alternatively, throw away that PictureBox; use a Panel instead, and in its OnPaint method, draw the different images with Graphics.DrawImage() at the required positions. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


          1 Reply Last reply
          0
          • A Ajay k_Singh

            If you are going to show more than one images on a single picture box, you may try creating a new image containing all images which you want to show. Following code will show two images img1.jpg and img2.jpg on the same picture box, by drawing them on a third image; second image will be drawn at the bottom of the first image- -----------------------------Start Code----------------------------- System.Drawing.Bitmap MergedImage; System.Drawing.Image Image1 = Image.FromFile("C:\\img1.jpg"); System.Drawing.Image Image2 = Image.FromFile("C:\\img2.jpg"); if (Image1.Width > Image2.Width) { MergedImage = new Bitmap(Image1.Width, Image1.Height + Image2.Height); } else { MergedImage=new Bitmap(Image2.Width,Image1.Height + Image2.Height); } Graphics g = Graphics.FromImage(MergedImage); g.DrawImage(Image1, 0, 0); g.DrawImage(Image2, 0, Image1.Height); this.pictureBox1.Image = MergedImage; g.Dispose(); --------------------------------------End Code------------------------------- I hope this helps:). -Dave.

            Dave Traister, ComponentOne LLC. www.componentone.com

            O Offline
            O Offline
            Ofori Boadu
            wrote on last edited by
            #5

            Thank you Dave I tried it and it worked perfectly.

            a novice

            1 Reply Last reply
            0
            • A Ajay k_Singh

              If you are going to show more than one images on a single picture box, you may try creating a new image containing all images which you want to show. Following code will show two images img1.jpg and img2.jpg on the same picture box, by drawing them on a third image; second image will be drawn at the bottom of the first image- -----------------------------Start Code----------------------------- System.Drawing.Bitmap MergedImage; System.Drawing.Image Image1 = Image.FromFile("C:\\img1.jpg"); System.Drawing.Image Image2 = Image.FromFile("C:\\img2.jpg"); if (Image1.Width > Image2.Width) { MergedImage = new Bitmap(Image1.Width, Image1.Height + Image2.Height); } else { MergedImage=new Bitmap(Image2.Width,Image1.Height + Image2.Height); } Graphics g = Graphics.FromImage(MergedImage); g.DrawImage(Image1, 0, 0); g.DrawImage(Image2, 0, Image1.Height); this.pictureBox1.Image = MergedImage; g.Dispose(); --------------------------------------End Code------------------------------- I hope this helps:). -Dave.

              Dave Traister, ComponentOne LLC. www.componentone.com

              O Offline
              O Offline
              Ofori Boadu
              wrote on last edited by
              #6

              I am trying to pull a text from a database and display it in the picture box under the images. I am getting errors though. Any idea how I can do that?

              a novice

              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