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
panJacekAsked:
Who is Participating?
 
Meir RivkinConnect With a Mentor Full 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
 
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
p_davisCommented:
and saving it to a file or drawing it to another picturebox?
0
 
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_davisConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.