none
Embed an Image into another Image

    Question

  • Hi,

    I want ot embed an image into another image. Can anyone suggest me regarding this...

    Suppose I want to embed a company logo onto an image.

    Regards

    RaiderZ
    Friday, April 18, 2008 10:23 PM

Answers

  • The following code shows how to load an image from a file, overlay another image on it, and then save the results to a file.  The overlay file should probably be a format that supports transparency, such as PNG, for good results.

     

    VB:

     

    Code Snippet

    Dim bmp As Bitmap = Bitmap.FromFile(initialFileName)

     

    'This draws another image as an overlay on top of bmp in memory.

    'There are additional forms of DrawImage; there are ways to fully specify the

    'source and destination rectangles. Here, we just draw the overlay at position (0,0).

     

    Using g As Graphics = Graphics.FromImage(bmp)

    g.DrawImage(Bitmap.FromFile(overlayFileName), 0, 0)

    End Using

     

    bmp.Save(saveAsFileName, System.Drawing.Imaging.ImageFormat.Png)

     

    C#:

     

    Code Snippet

    Bitmap bmp = Bitmap.FromFile(initialFileName);

     

    // This draws another image as an overlay on top of bmp in memory.

    // There are additional forms of DrawImage; there are ways to fully specify the

    // source and destination rectangles. Here, we just draw the overlay at position (0,0).

     

    using (Graphics g = Graphics.FromImage(bmp))

    {

    g.DrawImage(Bitmap.FromFile(overlayFileName), 0, 0);

    }

     

    bmp.Save(saveAsFileName, System.Drawing.Imaging.ImageFormat.Png);

     

    Saturday, April 19, 2008 1:57 AM

All replies

  • The following code shows how to load an image from a file, overlay another image on it, and then save the results to a file.  The overlay file should probably be a format that supports transparency, such as PNG, for good results.

     

    VB:

     

    Code Snippet

    Dim bmp As Bitmap = Bitmap.FromFile(initialFileName)

     

    'This draws another image as an overlay on top of bmp in memory.

    'There are additional forms of DrawImage; there are ways to fully specify the

    'source and destination rectangles. Here, we just draw the overlay at position (0,0).

     

    Using g As Graphics = Graphics.FromImage(bmp)

    g.DrawImage(Bitmap.FromFile(overlayFileName), 0, 0)

    End Using

     

    bmp.Save(saveAsFileName, System.Drawing.Imaging.ImageFormat.Png)

     

    C#:

     

    Code Snippet

    Bitmap bmp = Bitmap.FromFile(initialFileName);

     

    // This draws another image as an overlay on top of bmp in memory.

    // There are additional forms of DrawImage; there are ways to fully specify the

    // source and destination rectangles. Here, we just draw the overlay at position (0,0).

     

    using (Graphics g = Graphics.FromImage(bmp))

    {

    g.DrawImage(Bitmap.FromFile(overlayFileName), 0, 0);

    }

     

    bmp.Save(saveAsFileName, System.Drawing.Imaging.ImageFormat.Png);

     

    Saturday, April 19, 2008 1:57 AM
  • Thanks Binary Coder. Really appreciate your help.
    Monday, April 21, 2008 2:52 PM