En un principio yo también veo mal ofrecer ayuda a quien lo pide todo hecho sin mostrar código alguno, pero me he dado cuenta de que un "ejercicio" o utilidad cómo esta me faltaba en mi librería personal de códigos y me ha llamado la atención el desarrollar este tipo de utilidad para un uso genérico, ya que lo hago pues lo comparto.
Imagen trasera e imagen delantera Superposición (opaca)Código fuente ''' <remarks>
''' *****************************************************************
''' Snippet Title: Overlay Images
''' Code's author: Elektro
''' Date Modified: 30-April-2015
''' *****************************************************************
''' </remarks>
''' <summary>
''' Overlay an image over a background image.
''' </summary>
''' <param name="backImage">The background image.</param>
''' <param name="topImage">The topmost image.</param>
''' <param name="topPosX">An optional adjustment of the top image's "X" position.</param>
''' <param name="topPosY">An optional adjustment of the top image's "Y" position.</param>
''' <returns>The overlayed image.</returns>
''' <exception cref="ArgumentNullException">backImage or topImage</exception>
''' <exception cref="ArgumentException">Image bounds are greater than background image.;topImage</exception>
Public Shared Function OverlayImages(ByVal backImage As Image,
ByVal topImage As Image,
Optional ByVal topPosX As Integer = 0,
Optional ByVal topPosY As Integer = 0) As Image
If backImage Is Nothing Then
Throw New ArgumentNullException(paramName:="backImage")
ElseIf topImage Is Nothing Then
Throw New ArgumentNullException(paramName:="topImage")
ElseIf (topImage.Width > backImage.Width) OrElse
(topImage.Height > backImage.Height) Then
Throw New ArgumentException(message:="Image bounds are greater than background image.", paramName:="topImage")
Else
topPosX += CInt((backImage.Width / 2) - (topImage.Width / 2))
topPosY += CInt((backImage.Height / 2) - (topImage.Height / 2))
Dim bmp As New Bitmap(backImage.Width, backImage.Height)
Using canvas As Graphics = Graphics.FromImage(bmp)
canvas.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
canvas.DrawImage(image:=backImage,
destRect:=New Rectangle(0, 0, bmp.Width, bmp.Height),
srcRect:=New Rectangle(0, 0, bmp.Width, bmp.Height),
srcUnit:=GraphicsUnit.Pixel)
canvas.DrawImage(image:=topImage,
destRect:=New Rectangle(topPosX, topPosY, topImage.Width, topImage.Height),
srcRect:=New Rectangle(0, 0, topImage.Width, topImage.Height),
srcUnit:=GraphicsUnit.Pixel)
canvas.Save()
End Using
Return bmp
End If
End Function
Traducción online a C#/// <remarks>
/// *****************************************************************
/// Snippet Title: Overlay Images
/// Code's author: Elektro
/// Date Modified: 30-April-2015
/// *****************************************************************
/// </remarks>
/// <summary>
/// Overlay an image over a background image.
/// </summary>
/// <param name="backImage">The background image.</param>
/// <param name="topImage">The topmost image.</param>
/// <param name="topPosX">An optional adjustment of the top image's "X" position.</param>
/// <param name="topPosY">An optional adjustment of the top image's "Y" position.</param>
/// <returns>The overlayed image.</returns>
/// <exception cref="ArgumentNullException">backImage or topImage</exception>
/// <exception cref="ArgumentException">Image bounds are greater than background image.;topImage</exception>
public static Image OverlayImages(Image backImage, Image topImage, int topPosX = 0, int topPosY = 0)
{
if (backImage == null) {
throw new ArgumentNullException
(paramName
: "backImage");
} else if (topImage == null) {
throw new ArgumentNullException
(paramName
: "topImage");
} else if ((topImage.Width > backImage.Width) || (topImage.Height > backImage.Height)) {
throw new ArgumentException
("Image bounds are greater than background image.",
"topImage");
} else {
topPosX += Convert.ToInt32((backImage.Width / 2) - (topImage.Width / 2));
topPosY += Convert.ToInt32((backImage.Height / 2) - (topImage.Height / 2));
Bitmap bmp
= new Bitmap
(backImage
.Width, backImage
.Height);
using (Graphics canvas = Graphics.FromImage(bmp)) {
canvas.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic;
canvas
.DrawImage(image
: backImage, destRect
: new Rectangle
(0,
0, bmp
.Width, bmp
.Height), srcRect
: new Rectangle
(0,
0, bmp
.Width, bmp
.Height), srcUnit
: GraphicsUnit
.Pixel); canvas
.DrawImage(image
: topImage, destRect
: new Rectangle
(topPosX, topPosY, topImage
.Width, topImage
.Height), srcRect
: new Rectangle
(0,
0, topImage
.Width, topImage
.Height), srcUnit
: GraphicsUnit
.Pixel);
canvas.Save();
}
return bmp;
}
}
//=======================================================
//Service provided by Telerik (www.telerik.com)
//=======================================================
Modo de empleo (el mismo que he usado para generar el ejemplo de superposición de arriba)Dim backImg As Image = Image.FromFile("C:\back.jpg")
Dim topImg As Image = Image.FromFile("C:\top.png")
Dim overlay As Image = OverlayImages(backImg, topImg, topPosX:=+5, topPosY:=-15)
overlay.Save("C:\Overlay.jpg", Imaging.ImageFormat.Jpeg)
Process.Start("C:\Overlay.jpg")
Saludos