locked
Merge Image RRS feed

  • Question

  • User916522668 posted

    Hi everybody. I want to merge image(image format png)I use this code

     string strImagePath1 = Server.MapPath("es00.png");
                string strImagePath2 = Server.MapPath("es01.png");
             
                Image firstImage = Image.FromFile(strImagePath1);
                Graphics objGraphics = Graphics.FromImage(firstImage);
                Image secondImage = Image.FromFile(strImagePath2);
             
                int iFirstImageWidth = firstImage.Width;
                int iFirstImageHeight = firstImage.Height;
                int iSecondImageWidth = secondImage.Width;
                int iSecondImageHeight = secondImage.Height;
    
    
                int xPos = (iFirstImageWidth - iSecondImageWidth) / 2;
                int yPos = (iFirstImageHeight - iSecondImageHeight ) / 2;
    
                objGraphics.DrawImage(secondImage, new Point(xPos, yPos));
    
                Response.ContentType = "image/PNG";
    
                firstImage.Save(Server.MapPath("MergeImage1.png"), ImageFormat.Png);

    But How can I merge 7pictures to use this code?

    Best Regards

    Friday, March 18, 2011 5:49 AM

Answers

  • User916522668 posted

    I use this code. I fix it. Thanks again

              string strImagePath = Server.MapPath("es.png");
                string strImagePath1 = Server.MapPath("es00.png");
                string strImagePath2 = Server.MapPath("es01.png");
                string strImagePath3 = Server.MapPath("es02.png");
                string strImagePath4 = Server.MapPath("es03.png");
                string strImagePath5 = Server.MapPath("es04.png");
                string strImagePath6 = Server.MapPath("es05.png");
                string strImagePath7 = Server.MapPath("es06k0.png");
    
    
    
                Image img = Image.FromFile(strImagePath);
                Graphics g = Graphics.FromImage(img);
                g.DrawImage(Image.FromFile(strImagePath1), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath2), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath3), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath4), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath5), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath6), new Point(0, 0));
                g.DrawImage(Image.FromFile(strImagePath7), new Point(0, 0));
    
                img.Save(Server.MapPath("MergeImage1.png"), ImageFormat.Png);
                Response.ContentType = "image/PNG";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 18, 2011 6:05 AM