• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Composing bitmap from small bitmaps.

Hello Experts :-)

I am a C# newbie.

I have some small bitmaps saved against PictureBox'es.

I would like to compose new bitmap from selected small bitmaps saved against PictureBoxe'es.

How can I do it?

Thx

panJacek
0
panJacek
Asked:
panJacek
  • 4
  • 2
  • 2
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
what do u mean by "composing"?
just duplicate the bitmap?
0
 
panJacekAuthor Commented:
I mean composing big bitmap containing 16 small bitmaps in a 4x4 pattern.

panJacek
0
 
p_davisCommented:
and saving it to a file or drawing it to another picturebox?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
panJacekAuthor Commented:
p_davis:

drawing it to another PictureBox

panJacek
0
 
p_davisCommented:
does it matter how the other bitmaps are placed?

if not you could simply get the bounds of the picture box in a drawing event, and then with the width of that determine the size of your bitmaps so you can fit 4 across.

begin at the left side bounds of the pic box and then after you draw your first use the right side bounds of it to place your next -- once you have four in a row use the left side bounds of the pic box again and the bottom of the top row to determine placement..... etc.
0
 
p_davisCommented:
or you can simply create a bitmap in memory and use the graphics object to draw to it in the manner i have sugested starting with the left bounds of the bitmap and then simply set your pic box image property to it, when you are done.
0
 
p_davisCommented:
i didn't fully test but this should help get you on your way -- the mode stuff at the start is for highest quality.
Bitmap compBitmap = new Bitmap(picBox.Width, picBox.Height);
Graphics g = Graphics.FromImage(compBitmap);

g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;


//figure out your sizing -- if you need help with that then i will help
ImageAttributes ia = new ImageAttributes();
g.DrawImage(picBox1.Image, new Rectangle(0, 0, compBitmap.Width/4, compBitmap.Height/4), 0, 0, compBitmap.Width/4, compBitmap.Height/4, GraphicsUnit.Pixel, ia);

//you will have to have local members for size of bitmaps and such to make it simple for placment.
                       

Open in new window

0
 
Meir RivkinFull stack Software EngineerCommented:
pictureBox1.Image is your small bitmap, c:\temp\1.jpg is the output.

here's the code:

Bitmap srcbmp = new Bitmap(pictureBox1.Image);
            Bitmap bmp = new Bitmap(srcbmp.Width * 4, srcbmp.Height * 4);
            try
            {

                for (int w = 0; w < 4; w++)
                {
                    for (int h = 0; h < 4; h++)
                    {
                        for (int i = 0; i < srcbmp.Width; i++)
                        {
                            for (int j = 0; j < srcbmp.Height; j++)
                            {
                                bmp.SetPixel(i + (w * srcbmp.Width), j + (h * srcbmp.Height), srcbmp.GetPixel(i, j));
                            }
                        }
                    }
                }


            }
            catch (Exception ex)
            {

            }
            bmp.Save(@"c:\temp\1.jpg");
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now