none
Image Manipulation using c#: Help

    Question

  • Hi. What i want to do is to create an application that fills a certaing image with its small thimbnails. Lets say i have a picture and I have created its thumbnail....whats the way to fill the initial image with its thumbnails
    I have tried with the following code but it does not seem to be working
            private void button1_Click(object sender, EventArgs e)
            {
                Color clr;
                Bitmap bmp = new Bitmap(pictureBox1.Image);
                Bitmap bmp2 = new Bitmap(CreateThumbnail(bmp));
                int initialX = 0;
                int initialY = 0;
                for (int x = initialX; x < bmp.Width; x++)
                {
                    for (int y = initialY; y < bmp.Height; y++)
                    {
                        for (int xSmall = 0; xSmall < bmp2.Width; xSmall++)
                        {
                            for (int ySmall = 0; ySmall < bmp2.Height; ySmall++)
                            {
                                clr = bmp2.GetPixel(xSmall, ySmall);
                                bmp.SetPixel(xSmall, ySmall, clr);
                            }
                        }
                    }
                }
                initialX = initialX + bmp2.Width;
                initialY = initialY + bmp2.Height;
                pictureBox1.Image = bmp;

            }
            public bool ThumbnailCallback()
            {
                return false;
            }
            public Image CreateThumbnail(Bitmap bmp)
            {
                Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                return bmp.GetThumbnailImage(20, 20, myCallback, IntPtr.Zero);
            }


    Any help would be greatly appreciated...
    I am still a newbie so do not be rude please...
    thanks!
    reg: KC
    Tuesday, May 02, 2006 7:59 PM

Answers

  • Uh,....

    Lets say your images are 20 by 20 pixels and you want to have 100 on one thumbnail image, try it similar to this (I cannot write the full oce now, but it should give you the idea):
    Considering you have the images you want to have as thumbnails in a list.

    Bitmap bmp = new Bitmap(200,200);
    Graphics g = Graphics.FromImage(bmp);
    for (int i=0; i<100; i++)
    {
      g.DrawImage(images[ i ], (i%10*20), (i/10), 20, 20);
    }

    Tuesday, May 02, 2006 8:05 PM
  • John's reply is correct, except for a small omission:

    g.DrawImage (images [ i ], (i%10) * 20, (i / 10) * 20, 20, 20);

    As for your code, I didn't have a chance to test it, yet there are two errors you may want to review:

    1) bmp.SetPixel (xSmall, ySmall, clr);
    you probably meant: bmp.SetPixel (x, y, clr);

    2) initialY = initialY + bmp2.Height;
    you are incrementing both initialX and initialY at the same time. This means that your thumbnails will be drawn diagonally (you don't see this because of the previous problem).

    Another note: setting pixels one at a time will not give you an acceptable performance, so by all means use something along what John Doe proposed. Anyway, if you really had to do that, it's never a good idea to scan bitmaps vertically, as you change page more often that way.

    Regards,
    --mc

    Tuesday, May 02, 2006 9:26 PM

All replies

  • Uh,....

    Lets say your images are 20 by 20 pixels and you want to have 100 on one thumbnail image, try it similar to this (I cannot write the full oce now, but it should give you the idea):
    Considering you have the images you want to have as thumbnails in a list.

    Bitmap bmp = new Bitmap(200,200);
    Graphics g = Graphics.FromImage(bmp);
    for (int i=0; i<100; i++)
    {
      g.DrawImage(images[ i ], (i%10*20), (i/10), 20, 20);
    }

    Tuesday, May 02, 2006 8:05 PM
  • John's reply is correct, except for a small omission:

    g.DrawImage (images [ i ], (i%10) * 20, (i / 10) * 20, 20, 20);

    As for your code, I didn't have a chance to test it, yet there are two errors you may want to review:

    1) bmp.SetPixel (xSmall, ySmall, clr);
    you probably meant: bmp.SetPixel (x, y, clr);

    2) initialY = initialY + bmp2.Height;
    you are incrementing both initialX and initialY at the same time. This means that your thumbnails will be drawn diagonally (you don't see this because of the previous problem).

    Another note: setting pixels one at a time will not give you an acceptable performance, so by all means use something along what John Doe proposed. Anyway, if you really had to do that, it's never a good idea to scan bitmaps vertically, as you change page more often that way.

    Regards,
    --mc

    Tuesday, May 02, 2006 9:26 PM
  • Hey, I did not test it ;) I was just typing it freely, so if that is the only error, I must have a really good day :D - so no warranties on posted code here....
    Tuesday, May 02, 2006 9:39 PM
  • I didn't test it either ;) just noticed the obvious typo and tried to avoid our OP a little frustration. No offence intended.

    Cheers
    --mc

    Tuesday, May 02, 2006 9:42 PM
  • thank you all guys.....everything was an enormous help to me
    appreciate it
    thanks again
    Tuesday, May 02, 2006 10:10 PM