Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB .NET Visual-Studio
Hello,
 
I have a Loop that generates an ex amount of PictureBoxes in a FLowLayoutPanel. I am wodering if anyone was able to help me turn every picturebox in the flowlayoutpanel into one image.
 
Is this possible?
 
Can anyone help me?
 
Thanks.
Posted 3-Apr-13 1:18am
Comments
Karthik Harve at 3-Apr-13 6:24am
   
your question is not clear, for a picture box, you might specified an image to display. so, you will have your image., then what do you want to make into an image ?
SmashApps at 3-Apr-13 6:29am
   
Sorry.
 
I have a flow layout panel. I have code that runs a loop that generates like 200 pictureboxes. I want to be able to save ONE image from ALL the pictureboxes. The pictureboxes don't have an image just a back color. So basically they all form one image.
ThePhantomUpvoter at 3-Apr-13 6:59am
   
You have a design problem. There is no reason at all to create 200 pictureboxes. And what you are asking still does not make sense. If you have 200 pictureboxes and no image then you do not have any image to save so where do you think that this image data is coming from? You are essentially asking how to create an image out of nothing at all. Just create a blank bitmap and save it to disk.
SmashApps at 3-Apr-13 7:01am
   
Well the pictureboxes are used as grid, I couldn't think of a better way. The program is a Pixel art program you do pixel drawings. You select a color and click on each picturebox and its color changes.
 
I know I don't have an image, I want to create an image out of the pictureboxes backcolors.
Kschuler at 3-Apr-13 11:48am
   
I'm guessing there is a better way to do that. You might want to research the graphic's class: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx
Or if the whole point was that you didn't want to get real technical...I guess you could google for "VB.Net Merging Images" or "VB.Net Combining Images" I bet you could find something with those keywords.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In my TeboCam open source application I do this by stitching a list of bitmaps into one image.
Below is the method that does this:
 
        /// <summary>
        /// using a List of Bitmaps as input a Bitmap patchword is returned 
        /// </summary>
        /// <returns>Bitmap</returns>
        public static Bitmap getMosaicBitmap(int imagesPerRow)
        {
 
            try
            {
 
                List<bitmap> imageItems = bitmaps;
                int imgCount = imageItems.Count;
                int imagesX;
                int xCount = 1;
                int xPos = 0;
                int yPos = 0;
 
                //let's save some image real estate if we can
                //if there are less images than wil fit into one row - trim the row size
                if (imgCount < imagesPerRow)
                {
                    imagesX = imgCount;
                }
                else
                {
                    imagesX = imagesPerRow;
                }
 
                //get the width and height of the images()images must hasve same width and height)
                int width = imageItems[0].Width;
                int height = imageItems[0].Height;
 
                //row count is rounded down count of images divided by columns
                int rows = (int)Math.Floor((decimal)imgCount / (decimal)imagesX);
 
                //if there is a remainder in dividing the count of images by columns
                //add an extra row to the row count
                bool remainder = decimal.Remainder((decimal)imgCount, (decimal)imagesX) > 0m;
                if (remainder) rows++;
 
                //we now know the dimensions of the Bitmap so let's create it
                Bitmap mosaicImage = new System.Drawing.Bitmap(imagesX * width, rows * height);
 
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(mosaicImage))
                {
 
                    //fill the mosaic in black first
                    g.Clear(System.Drawing.Color.Black);
 
                    for (int i = 0; i < imgCount; i++)
                    {
 
                        //iterate through images adding to mosaic
                        //images are added from let to right then down one and row left to right etc.
                        g.DrawImage(imageItems[i], new System.Drawing.Rectangle(xPos, yPos, imageItems[i].Width, imageItems[i].Height));
 
                        xCount++;
 
                        if (xCount > imagesX)
                        {
                            xPos = 0;
                            xCount = 1;
                            yPos = yPos + height;
 
                        }
                        else
                        {
                            xPos = xPos + width;
                        }
 
                    }
 
                    imageItems.Clear();
                    return mosaicImage;
 

                }
 

 
            }
 
            catch
            {
                return null;
            }
 
        }
 
</bitmap>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100