locked
How to create a collate effect with 2 images?

    Question

  •  

    Dear members, Hi for everybody!

     

    Houston - got a trouble here....

    I am developing a simple application that is as follows:

    1) Given 2 images ( same format and height x width), generate a 3rd image which is image 1 pasted (binded) by the side of image 2. It´s a collate effect.

    2) Given 3 images (same format and h x w), collate these 3 images (one by the side of the other) and generate a 4th image with this collate effect.

    3) Given 4 images (same format and h x l), collate these 4 images ( one by the side of the other) and generate a 5 th image with this collate effect.

    4) Given (n-1) images, collate these (n-1) images ( one by the side of the other) and generate a n-th image with these collate effect.

     

    Could you help me in this issue?

     

    Thanks in advance!

    mslf

     

    Saturday, April 07, 2007 9:09 PM

Answers

  • Here is how I would do it:

     

    Code Snippet

            //Returns a bitmap image which is image1 + image2

            private Bitmap TileImages(Bitmap image1, Bitmap image2)

            {

                int x = image1.Size.Width + image2.Size.Width;

                int y = image1.Size.Height;

     

                Bitmap image3 = new Bitmap(x, y);

     

                Graphics g = Graphics.FromImage(image3);

                g.DrawImageUnscaled(image1, 0, 0);

                g.DrawImageUnscaled(image2, image1.Size.Width, 0);

                g.Dispose();

                return image3;

            }

     

     

    Sunday, April 08, 2007 1:11 PM
  • Thank you Mr. Jr, I will use this algorithm you wrote, very good!

     

    Before reach the point that draw image3 from adding image1 and image2 I will read the image from a file.

    I wrote this code below just to test but I got the following error:

     

    private void button1_Click(object sender, EventArgs e)

    {

                      Bitmap image3;

                      image3 = System.Drawing.Bitmap.FromFile("C:figur22.bmp");

    }

     

    Error 1 

    Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'.

    An explicit conversion exists (are you missing a cast?) 

     

    Can you help me?

     

    Regards,

     

    Sunday, April 08, 2007 8:50 PM
  • Try something like this:

     

    Code Snippet

                Bitmap image1 = new Bitmap(@"C:\image1.bmp");

                Bitmap image2 = new Bitmap(@"C:\image2.bmp");

     

                Bitmap image3 = TileImages(image1, image2);

     

                image3.Save(@"C:\image3.bmp");

     

     

    Sunday, April 08, 2007 9:04 PM
  • Jr:

     

    Awesome! 

    Thanks a lot for the precious time you spent working on this issue,  , I could not reply yesterday because I had to went out.

     

    Best Regards,

     

    Monday, April 09, 2007 5:23 PM

All replies

  • Here is how I would do it:

     

    Code Snippet

            //Returns a bitmap image which is image1 + image2

            private Bitmap TileImages(Bitmap image1, Bitmap image2)

            {

                int x = image1.Size.Width + image2.Size.Width;

                int y = image1.Size.Height;

     

                Bitmap image3 = new Bitmap(x, y);

     

                Graphics g = Graphics.FromImage(image3);

                g.DrawImageUnscaled(image1, 0, 0);

                g.DrawImageUnscaled(image2, image1.Size.Width, 0);

                g.Dispose();

                return image3;

            }

     

     

    Sunday, April 08, 2007 1:11 PM
  • Thank you Mr. Jr, I will use this algorithm you wrote, very good!

     

    Before reach the point that draw image3 from adding image1 and image2 I will read the image from a file.

    I wrote this code below just to test but I got the following error:

     

    private void button1_Click(object sender, EventArgs e)

    {

                      Bitmap image3;

                      image3 = System.Drawing.Bitmap.FromFile("C:figur22.bmp");

    }

     

    Error 1 

    Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'.

    An explicit conversion exists (are you missing a cast?) 

     

    Can you help me?

     

    Regards,

     

    Sunday, April 08, 2007 8:50 PM
  • Try something like this:

     

    Code Snippet

                Bitmap image1 = new Bitmap(@"C:\image1.bmp");

                Bitmap image2 = new Bitmap(@"C:\image2.bmp");

     

                Bitmap image3 = TileImages(image1, image2);

     

                image3.Save(@"C:\image3.bmp");

     

     

    Sunday, April 08, 2007 9:04 PM
  • Jr:

     

    Awesome! 

    Thanks a lot for the precious time you spent working on this issue,  , I could not reply yesterday because I had to went out.

     

    Best Regards,

     

    Monday, April 09, 2007 5:23 PM