Introduction
I searched a lot for an easy way to merge two bitmaps using .NET code. I always get referred back to GDI bitblt, which isn't friendly to .NET style images. Or managing alpha channels. I suppose I missed something...? Finally, I devised a simple method to apply variable transparency to any .NET bitmap. This doesn't actually blend colors between two bitmaps in the real sense, but sets a percentage of transparency in bitmap A, which when used as a texture brush applied to bitmap B, dose a pretty good job.
Specifying the correct rectangles would allow the typical overlays. This example tiles overlay when you view screen 2. That is the code that uses this brush, which is not shown here. This code represents transparency as white. This code allows you to blend bitmaps without managing alpha channels.
Confusing that the Windows color set of 16 million hasn't reserved a transparent color. The Bitmap.MakeTransparent
allows you to assign the transparent color. This code will assign transparent color in a nice blend that works.
This code is easy, and works quickly. Just use the bitmap from this code as a texture brush with bitmap.maketransparency(system.drawing.color.white)
.
Public Sub SetAlphaVary(ByRef abm As Image)
=====================================================
Dim r1 As RectangleF
r1.X = 0
r1.Y = 0
r1.Width = abm.Width
r1.Height = abm.Height
graphics1.Dispose()
graphics1 = Graphics.FromImage(abm)
Dim path1 As New System.Drawing.Drawing2D.GraphicsPath
path1.FillMode = Drawing2D.FillMode.Alternate
path1.AddRectangle(r1)
Dim brush3 As New Drawing2D.HatchBrush _
(CInt(getarg2(MainForm.AlphaPercent.Text, "code")), _
System.Drawing.Color.White, System.Drawing.Color.Transparent)
graphics1.FillPath(brush3, path1)
brush3.Dispose()
path1.Dispose()
End Sub
The images below are from my project DesignLab(c) 2007. This program can manage bitmaps up to 7200x7200, and has been used to print out designs as large as 56"x17" on my Epson7800. We have printed designs to Silk for Silk Scarves etc.