I found this code here:
Private _BackgroundColours As New List(Of String)() From { _
"339966", _
"3366CC", _
"CC33FF", _
"FF5050" _
}
Public Function GenerateRactangle(firstName As String, lastName As String) As MemoryStream
Dim imgSize() As Integer = {800, 800}
Dim avatarString As String = String.Format("{0}{1}", firstName(0), lastName(0)).ToUpper()
Dim bgColour = _BackgroundColours(New Random().[Next](0, _BackgroundColours.Count - 1))
Dim bmp As Bitmap = New Bitmap(imgSize(0), imgSize(1))
Dim sf As StringFormat = New StringFormat()
Dim ms As MemoryStream = New MemoryStream()
Dim font As Font = New Font("Arial", 172, FontStyle.Bold, GraphicsUnit.Pixel)
Dim graphics__1 As Graphics = Nothing
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
graphics__1 = Graphics.FromImage(bmp)
graphics__1.Clear(DirectCast(New ColorConverter().ConvertFromString("#" + bgColour), Color))
graphics__1.SmoothingMode = SmoothingMode.AntiAlias
graphics__1.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
graphics__1.DrawString(avatarString, font, New SolidBrush(Color.WhiteSmoke), New RectangleF(0, 0, imgSize(0), imgSize(1)), sf)
graphics__1.Flush()
bmp.Save(ms, ImageFormat.Png)
Return ms
End Function
On stackoverflow and it works great. However, I am in need of using a transparent PNG image in the background with the color changing background color.
What it currently looks like:
What I am looking for it to look like:
With the PNG image being this that was added:
I am hoping someone with more knowledge about the graphics calls can let me know how to go about doing this.