public static void DrawColorPickerIcon(Graphics g, Color color, Rectangle rect, int holeSize = 0) { if (color.A < 255) { using (Image checker = ImageHelpers.CreateCheckerPattern(rect.Width / 2, rect.Height / 2)) { g.DrawImage(checker, rect); } } using (SolidBrush brush = new SolidBrush(color)) { g.FillRectangle(brush, rect); } g.DrawRectangleProper(Pens.Black, rect); if (holeSize > 0) { g.CompositingMode = CompositingMode.SourceCopy; Rectangle holeRect = new Rectangle(rect.Width / 2 - holeSize / 2, rect.Height / 2 - holeSize / 2, holeSize, holeSize); g.FillRectangle(Brushes.Transparent, holeRect); g.DrawRectangleProper(Pens.Black, holeRect); } }
public static Image DrawCheckers(int width, int height) { Bitmap bmp = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(bmp)) using (Image checker = ImageHelpers.CreateCheckerPattern()) using (Brush checkerBrush = new TextureBrush(checker, WrapMode.Tile)) { g.FillRectangle(checkerBrush, new Rectangle(0, 0, bmp.Width, bmp.Height)); } return(bmp); }
public static Image DrawCheckers(Image img, int size, Color color1, Color color2) { Bitmap bmp = img.CreateEmptyBitmap(); using (Graphics g = Graphics.FromImage(bmp)) using (Image checker = ImageHelpers.CreateCheckerPattern(size, size, color1, color2)) using (Brush checkerBrush = new TextureBrush(checker, WrapMode.Tile)) using (img) { g.FillRectangle(checkerBrush, new Rectangle(0, 0, bmp.Width, bmp.Height)); g.SetHighQuality(); g.DrawImage(img, 0, 0, img.Width, img.Height); } return(bmp); }