I need to generate a large amount of color swatches (bitmaps) to be used in a GridView
. In order to create them, i tried to build the bitmap like this:
bitmap = Eto.Drawing.Bitmap(20, 20, Eto.Drawing.PixelFormat.Format32bppRgb)
color = Eto.Drawing.Colors.AliceBlue
graphics = Eto.Drawing.Graphics(bitmap)
graphics.Clear(color)
The process to create 6 empty bitmaps (20x20 pixels) like above, takes 6 seconds which cannot be right. So i tried to clear the graphics with a solid brush like this:
bitmap = Eto.Drawing.Bitmap(20, 20, Eto.Drawing.PixelFormat.Format32bppRgb)
color = Eto.Drawing.Colors.AliceBlue
brush = Eto.Drawing.SolidBrush(color)
graphics = Eto.Drawing.Graphics(bitmap)
graphics.Clear(brush)
without any change in speed. So i tried to draw a rectangle in my color into the graphics object which seems to work very fast:
bitmap = Eto.Drawing.Bitmap(20, 20, Eto.Drawing.PixelFormat.Format32bppRgb)
color = Eto.Drawing.Colors.Red
brush = Eto.Drawing.SolidBrush(color)
graphics = Eto.Drawing.Graphics(bitmap)
rectangle = Eto.Drawing.Rectangle(0, 0, 12, 12)
graphics.FillRectangle(brush, rectangle)
but the result is a black bitmap unless i add this at the end:
graphics.Dispose()
As soon as this line is added, the bitmap creation process runs as slow as before. Running out of ideas, iâve used bitmap.SetPixel(x,y,color)
in a double nested loop as reported here which seems to run slightly faster but with more than 100 swatches to generate, takes too long to be usable.
How can i generate these color swatches fast enough ?
thanks,
c.