' Copy the foreground image into a bitmap.
Dim phototouse As String
phototouse = "C:\inetpub\wwwroot\watermark.png"
Dim picForeground As System.Drawing.Bitmap = New System.Drawing.Bitmap(phototouse)
Dim fg_wid As Integer = picForeground.Width
Dim fg_hgt = picForeground.Height
Dim fg_bm As New Bitmap(fg_wid, fg_hgt)
Using gr As Graphics = Graphics.FromImage(fg_bm)
gr.DrawImage(picForeground, 0, 0, fg_wid, fg_hgt)
End Using
' Make the red pixels transparent.
fg_bm.MakeTransparent(Color.White)
Dim photo As String = photoname
' Make the result bitmap.
Dim picBackground As System.Drawing.Bitmap = New System.Drawing.Bitmap(localfolder & photo)
Dim bg_wid As Integer = picBackground.Width
Dim bg_hgt = picBackground.Height
Dim bg_bm As New Bitmap(bg_wid, bg_hgt)
If cy = 0 And cx = 0 Then
'Need to position photo in far left corner b/c pattern not found
cx = 0 ' Set to zero for logo in left bottom corner, set to bg_wid - 90 for logo in bottom right corner
cy = bg_hgt - 20
Else
'pattern found, adjust to cover the pattern
cx = cx - 2
cy = cy - 11
End If
Using gr As Graphics = Graphics.FromImage(bg_bm)
gr.DrawImage(picBackground, 0, 0, bg_wid, bg_hgt)
' Draw the foreground image on top.
gr.DrawImage(fg_bm, cx, cy, fg_wid, fg_hgt)
End Using
' Display the result.
Dim destfile As String = localfolder & photonewname
bg_bm.Save(destfile)
' We don't need the foreground bitmap any more.
fg_bm.Dispose()
|