locked
Embed image on image RRS feed

  • Question

  • User-1773939321 posted

    I want to embed a small image on a large iamge. For e.g I have an image back.jpg and front.jpg. The back.jpg will be large image and the front image will be small image.

    Here is the code i found below.


    private void GenererateGalleryImage(string baseImage, string smallImage)
            {
                Bitmap objImage = new Bitmap(baseImage);
                Bitmap objSmallImage = new Bitmap(smallImage);
                using (Graphics g = Graphics.FromImage(objImage))
                {
                    g.DrawImage(objSmallImage,50,50);
                    // there are 30-some overloads of DrawImage, but
                    // basically you use objSmallImage as the source,
                    // plus various ways of telling the method
                    // where to draw the smaller image.
                }
                objImage.Save(Response.OutputStream,  ImageFormat.Jpeg);
                objImage.Dispose();
                objSmallImage.Dispose();

            }

    I want to embed image propotionally as in the back image and front image.

    Friday, October 16, 2009 3:09 AM

Answers

  • User1923880652 posted

    Hi Hamza,

     Try

     

    private void GenererateGalleryImage(string baseImage, string smallImage)
            {
                Bitmap objImage = new Bitmap(baseImage);
                Bitmap objSmallImage = new Bitmap(smallImage);
                int wmWidth = objSmallImage.Width;
                int wmHeight = objSmallImage.Height;
                int xPosOfWm = (125 - (wmWidth / 2));
                int yPosOfWm = (125 - (wmHeight / 2));
              
                using (Graphics g = Graphics.FromImage(objImage))
                {
                    //g.DrawImage(objSmallImage,  50, 50);                
                    g.DrawImage(objSmallImage, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight));          
                }
                objImage.Save(Response.OutputStream, ImageFormat.Jpeg);
                objImage.Dispose();
                objSmallImage.Dispose();
    
            }

    It is via help of http://forums.asp.net/t/1416533.aspx


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2009 7:54 AM