Is that possible? I want to pass my custom color as a parameter and I want to receive an Image (rectangle for example).
Public Function createIcon(ByVal c As Color) As Bitmap
Dim g As Graphics
Dim Brush As New SolidBrush(c)
g.FillRectangle(Brush, New Rectangle(0, 0, 20, 20))
Dim bmp As New Bitmap(20, 20, g)
Return bmp
End Function
I tried this way and couldn’t success.
Bitmap: A canvas (in memory) that contains an image.Graphics: A tool set that allows you to draw on an associated canvas.With this in mind, here is the solution:
The
Usingblocks here merely serve the purpose of disposing the graphics resources properly (by automatically calling theirDisposemethod at the end of the block). You need to do this, otherwise you will leak graphics resources.