locked
Append two images to one image side by side RRS feed

  • Question

  • User779033375 posted

    Hi,

     Can we append two images to one image.

    Suppose I have "A" and "B" two charecters in two images.

    can I combine this two mages into one and show AB side by side in one image.

    Wednesday, February 18, 2009 12:16 AM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 12:33 AM
  • User1817007508 posted

    Hai Thanks for post,

    its good code and useful in some case.

    but My requirement is  to add images side by side.

    Hi,

    This is what i wrote for you, to combine two images side by side.

    Check it and let me know

    System.Drawing.Image ImageOne = System.Drawing.Image.FromFile(Server.MapPath(Image1.ImageUrl)); //replace path of image one with Image1.ImageUrl
            System.Drawing.Image ImageTwo = System.Drawing.Image.FromFile(Server.MapPath(Image2.ImageUrl)); //replace path of image two with Image2.ImageUrl
    
            int NewImageHeight = ImageOne.Height > ImageTwo.Height ? ImageOne.Height : ImageTwo.Height; //To calculate height of new image
            int NewImageWidth = ImageOne.Width + ImageTwo.Width; // width of new image
    
            
            Bitmap NewImageBmp = new Bitmap(NewImageWidth, NewImageHeight,PixelFormat.Format32bppArgb); // you can change the bpp as per your requirment. Size of image directly propotionate to bpp of image
    
            Graphics NewImageGrx = System.Drawing.Graphics.FromImage(NewImageBmp);
    
            NewImageGrx.DrawImageUnscaled(ImageOne,0,0); //draw first image at coordinate 0,0 
            NewImageGrx.DrawImageUnscaled(ImageTwo, ImageOne.Width, 0); //draw second image at coordinate image1.width,0
    
            string CombineImage = Guid.NewGuid().ToString() + ".jpg";
            NewImageBmp.Save(Server.MapPath("~/img/" + CombineImage), ImageFormat.Jpeg); // saving combined image. You can specify the ImageFormat as per your requirment.
    
            //disposing objects after use
            ImageOne.Dispose();
            ImageTwo.Dispose();
    
            NewImageBmp.Dispose();
            NewImageGrx.Dispose();
    
            //tow view combined image
            Image3.ImageUrl = "~/img/" + CombineImage;
     [:D]
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 6:18 AM

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 12:33 AM
  • User779033375 posted

     

    Hai Thanks for post,

    its good code and useful in some case.

    but My requirement is  to add images side by side.

     

    Wednesday, February 18, 2009 4:54 AM
  • User1817007508 posted

    Hai Thanks for post,

    its good code and useful in some case.

    but My requirement is  to add images side by side.

    Hi,

    This is what i wrote for you, to combine two images side by side.

    Check it and let me know

    System.Drawing.Image ImageOne = System.Drawing.Image.FromFile(Server.MapPath(Image1.ImageUrl)); //replace path of image one with Image1.ImageUrl
            System.Drawing.Image ImageTwo = System.Drawing.Image.FromFile(Server.MapPath(Image2.ImageUrl)); //replace path of image two with Image2.ImageUrl
    
            int NewImageHeight = ImageOne.Height > ImageTwo.Height ? ImageOne.Height : ImageTwo.Height; //To calculate height of new image
            int NewImageWidth = ImageOne.Width + ImageTwo.Width; // width of new image
    
            
            Bitmap NewImageBmp = new Bitmap(NewImageWidth, NewImageHeight,PixelFormat.Format32bppArgb); // you can change the bpp as per your requirment. Size of image directly propotionate to bpp of image
    
            Graphics NewImageGrx = System.Drawing.Graphics.FromImage(NewImageBmp);
    
            NewImageGrx.DrawImageUnscaled(ImageOne,0,0); //draw first image at coordinate 0,0 
            NewImageGrx.DrawImageUnscaled(ImageTwo, ImageOne.Width, 0); //draw second image at coordinate image1.width,0
    
            string CombineImage = Guid.NewGuid().ToString() + ".jpg";
            NewImageBmp.Save(Server.MapPath("~/img/" + CombineImage), ImageFormat.Jpeg); // saving combined image. You can specify the ImageFormat as per your requirment.
    
            //disposing objects after use
            ImageOne.Dispose();
            ImageTwo.Dispose();
    
            NewImageBmp.Dispose();
            NewImageGrx.Dispose();
    
            //tow view combined image
            Image3.ImageUrl = "~/img/" + CombineImage;
     [:D]
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 6:18 AM
  • User779033375 posted

     Hi ASP.NET Dev,

    Thank  you, Yes! It works.

     

    Thursday, February 19, 2009 12:09 AM
  • User-1789836585 posted

     hey !! even i need to put two images side by side..i used the above code but i encountered the following errors:

    1.the type or namespace name 'Bitmap' could not be found

    2.the type or namespace name 'Graphics' could not be found

    3.the name 'PixelFormat' does not exist in the current context

    4. the name 'ImageFormat' does not exist in the current context

    5. the name 'Image3' does not exist in the current context

    can u also tell me the format of giving the url because its not recognizing url i gave


    plzzzzz....help!! its urgent

    Thanks 

    Sunday, July 26, 2009 2:47 AM
  • User779033375 posted

     hey !! even i need to put two images side by side..i used the above code but i encountered the following errors:

    1.the type or namespace name 'Bitmap' could not be found

    2.the type or namespace name 'Graphics' could not be found

    3.the name 'PixelFormat' does not exist in the current context

    4. the name 'ImageFormat' does not exist in the current context

    5. the name 'Image3' does not exist in the current context

    can u also tell me the format of giving the url because its not recognizing url i gave


    plzzzzz....help!! its urgent

    Thanks 


    Have you included all namespaces

    Tuesday, July 28, 2009 12:41 AM
  • User-1789836585 posted

    system.drawing provides functionality for graphics..so hw can i get the error "namespace type graphics not there"

     also i came to know that

    *Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.*

    did you run your program at vista?? 

    Wednesday, July 29, 2009 10:42 AM
  • User-1789836585 posted

     and did you have to edit the code??

    Wednesday, July 29, 2009 10:43 AM
  • User779033375 posted

    I am running on XP 2

    make sure the path of image file is correct.

    or

    can you post your code here so I can review, if possible.

    Monday, August 3, 2009 3:17 AM
  • User1817007508 posted

    system.drawing provides functionality for graphics..so hw can i get the error "namespace type graphics not there"

     also i came to know that

    *Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.*

    did you run your program at vista?? 

     

    Hi nini_14,

    Are you using this code inside webservice method?

    can you post the code you integrated?

    Wednesday, August 5, 2009 4:34 AM