private void RenderImages() { Bitmap bmp = new Bitmap(this.Width, this.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(MouseOutBackgroundColor); if (!(ShapeImage == null)) { for (int y = 0; (y <= (ShapeImage.Height - 1)); y++) { for (int x = 0; (x <= (ShapeImage.Width - 1)); x++) { Color pixelColor = Color.FromArgb(ShapeImage.GetPixel(x, y).A, ShapeColor); g.FillRectangle(new SolidBrush(pixelColor), new Rectangle(x, y, 1, 1)); } } } _mouseOutImage = new Bitmap(bmp); g.Clear(MouseOverBackgroundColor); if (!(ShapeImage == null)) { for (int y = 0; (y <= (ShapeImage.Height - 1)); y++) { for (int x = 0; (x <= (ShapeImage.Width - 1)); x++) { Color pixelColor = Color.FromArgb(ShapeImage.GetPixel(x, y).A, ShapeColor); g.FillRectangle(new SolidBrush(pixelColor), new Rectangle(x, y, 1, 1)); } } } _mouseOverImage = new Bitmap(bmp); g.Clear(MouseDownBackgroundColor); if (!(ShapeImage == null)) { for (int y = 0; (y <= (ShapeImage.Height - 1)); y++) { for (int x = 0; (x <= (ShapeImage.Width - 1)); x++) { Color pixelColor = Color.FromArgb(ShapeImage.GetPixel(x, y).A, ShapeColor); g.FillRectangle(new SolidBrush(pixelColor), new Rectangle(x, y, 1, 1)); } } } _mouseDownImage = new Bitmap(bmp); g.Dispose(); bmp.Dispose(); }
protected override void OnLoad(EventArgs e) { if (ShapeImage != null) { this.Size = ShapeImage.Size; using (Region tmpRegion = new Region()) { tmpRegion.MakeEmpty(); using (Graphics g = Graphics.FromImage(ShapeImage)) { bool isMatch = false; Rectangle tmpRect = new Rectangle(0, 0, 0, 0); for (int x = 0; x < ShapeImage.Width; x++) { for (int y = 0; y < ShapeImage.Height; y++) { if (!isMatch) { if (ShapeImage.GetPixel(x, y).ToArgb() != TransparentColor.ToArgb()) { isMatch = true; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = 1; } } else { if (ShapeImage.GetPixel(x, y).ToArgb() == TransparentColor.ToArgb()) { isMatch = false; tmpRect.Height = y - tmpRect.Y; tmpRegion.Union(tmpRect); } } } if (isMatch) { isMatch = false; tmpRect.Height = ShapeImage.Height - tmpRect.Y; tmpRegion.Union(tmpRect); } } this.Region = tmpRegion.Clone(); } } } base.OnLoad(e); }