Displaying multiple images in a picture box
-
I am trying to display multiple images in a single picture box control. Any ideas?
a novice
-
I am trying to display multiple images in a single picture box control. Any ideas?
a novice
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
-
I am trying to display multiple images in a single picture box control. Any ideas?
a novice
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
-
I am trying to display multiple images in a single picture box control. Any ideas?
a novice
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
-
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
Thank you Dave I tried it and it worked perfectly.
a novice
-
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
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