How to merge two images

gopalakrishnan

New member
Joined
Dec 16, 2009
Messages
1
Programming Experience
Beginner
Hi to all.. I want to know how to merge two images. That is I'm having two images named like a.jpeg,b.jpeg. I want to place a.jpeg into b.jpeg to create c.jpeg. Help me to solve this..

Thanks in advance..
 
This should be what you're looking for. If you want to change where the image is placed change the x,y of the DrawImage method.

VB.NET:
		Dim imgOverlay As Bitmap = Image.FromFile("C:\Temp\Images\a.jpg")
		Dim imgBackground As Bitmap = Image.FromFile("C:\Temp\Images\b.jpg")
		Dim g As Graphics = Graphics.FromImage(imgBackground)
		imgOverlay.MakeTransparent(Color.White)
		g.DrawImage(imgOverlay, 0, 0)
		g.Dispose()
		imgBackground.Save("C:\Temp\Images\c.jpg")
 
To make the whole bitmap transparent (and thus, displaying it over a second one, both are visible):
VB.NET:
Function FadeBitmap(bmp As Bitmap, OpacityPercent As Single) As Bitmap
     Dim tempBmp As New Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb)
     OpacityPercent = Math.Min(OpacityPercent, 100)
     Using ia As New Imaging.ImageAttributes
         Dim cm As New Imaging.ColorMatrix
         cm.Matrix33 = OpacityPercent / 100.0F
         ia.SetColorMatrix(cm)
         Dim destpoints() As PointF = {New Point(0, 0), New Point(bmp.Width, 0), New Point(0, bmp.Height)}
         Using g As Graphics = Graphics.FromImage(tempBmp)
             g.Clear(Color.Transparent)
             g.DrawImage(bmp, destpoints, New RectangleF(Point.Empty, bmp.Size), GraphicsUnit.Pixel, ia)
         End Using
     End Using
     Return tempBmp
 End Function
 
Last edited by a moderator:
Back
Top