Created
December 8, 2021 11:55
-
-
Save Wampa842/c30ae509927cdc9fc971407d5be239ad to your computer and use it in GitHub Desktop.
Chequered bitmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class GridBitmap | |
{ | |
public static Bitmap Create(int repeatX, int repeatY, Size bitmapSize, Color foreground, Color background) | |
{ | |
// Check for division by zero | |
if (repeatX == 0 || repeatY == 0) | |
throw new ArgumentException("Division by zero."); | |
Bitmap bmp = new Bitmap(bitmapSize.Width, bitmapSize.Height); | |
Graphics g = Graphics.FromImage(bmp); | |
Brush fgBrush = new SolidBrush(foreground); | |
g.Clear(background); | |
SizeF size = new SizeF((float)bmp.Width / repeatX, (float)bmp.Height / repeatY); | |
for (int x = 0; x < repeatX; x += 2) | |
{ | |
for (int y = 0; y < repeatY; ++y) | |
{ | |
g.FillRectangle(fgBrush, (x + (y % 2)) * size.Width, y * size.Height, size.Width, size.Height); | |
} | |
} | |
g.Dispose(); | |
return bmp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment