Introduction
I know there are numerous examples of alpha blending stuff, but many are not true blends, such as the in one of my articles. Others call managing transparencies as blends, and some are truly complicated transforms and merges.
I have been convinced there would be a simple .NET solution like 5 lines of code... This is it..
Public Sub SetAlphaRGB(ByRef abm As Image)
Dim bitm As New Bitmap(abm)
Dim mxItems As Single()() = { _
New Single() {1, 0, 0, 0, 0}, _
New Single() {0, 1, 0, 0, 0}, _
New Single() {0, 0, 1, 0, 0}, _
New Single() {0, 0, 0, 128, 0}, _ Note that sets alpha at 128 50%
New Single() {0, 0, 0, 0, 1}}
Dim colorMatrix As New System.Drawing.Imaging.ColorMatrix(mxItems)
Dim imageAtt As New System.Drawing.Imaging.ImageAttributes()
imageAtt.SetColorMatrix(colorMatrix, _
System.Drawing.Imaging.ColorMatrixFlag.Default, _
System.Drawing.Imaging.ColorAdjustType.Bitmap)
so this routine can handle most of your image manipulations
Dim r1 As RectangleF
r1.X = 0
r1.Y = 0
r1.Width = abm.Width
r1.Height = abm.Height
Dim r2 As RectangleF
r2.X = 0
r2.Y = 0
r2.Width = bm.Width
r2.Height = bm.Height
graphics1.Dispose()
graphics1 = Graphics.FromImage(bm)
Dim brush3 As New TextureBrush(bitm, r1, imageAtt)
brush3.WrapMode = Drawing2D.WrapMode.Tile
graphics1.CompositingMode = Drawing2D.CompositingMode.SourceOver
graphics1.FillRectangle(brush3, r2)
graphics1.DrawImage(bitm, New Rectangle(0, 0, 1700, 1700), 0, 0,_
bitm.Width, bitm.Height, GraphicsUnit.Pixel, imageAtt)
brush3.Dispose()
graphics1.Dispose()
MainForm.PictureBox1.Refresh() SetGraphics(MainForm.PictureBox1)
End Sub
My granddaughter tiled over a DesignLab(c) 2007 design. This is at 128 Alpha (50%). This truly is about 5 lines of code. If you play with the image attributes, you can manage the threshold and gamma as well.