public void TestFillRect() { var image = new IndexedImage { Size = new Size(5, 5) }; ImagePainter.FillRect(image, new Rectangle(2, 1, 4, 2), 1); AssertImage( new[] { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, image); ImagePainter.FillRect(image, new Rectangle(1, 2, 2, 2), 2); AssertImage( new[] { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0 }, image); }
void PaintPageNumber(int number, int x, int y) { var numberString = number.ToString(); var numberSize = PageNumberPainter.GetTextSize(numberString); ImagePainter.FillRect(VisualImage, new Rectangle(x, y, numberSize.Width + 4, numberSize.Height + 4), WhiteColorArgb); PageNumberPainter.PaintText(numberString, VisualImage.Pixels, VisualImage.Size, new Point(x + 2, y + 2)); }
void IPainter.FillRectangle(int x, int y, int width, int height, int argb) { x += Shift.Width; y += Shift.Height; x = Math.Max(x, ClipRect.Left); y = Math.Max(y, ClipRect.Top); width = Math.Min(width, ClipRect.RightExclusive - x); height = Math.Min(height, ClipRect.BottomExclusive - y); ImagePainter.FillRect(Canvas, new Rectangle(x, y, width, height), argb); }
static void SetButtonColor(ButtonBase button, int argb) { const int ImageWidth = 20; var image = new IndexedImage { Size = new Size(ImageWidth, ImageWidth) }; ImagePainter.FillRect(image, new Rectangle(0, 0, ImageWidth, ImageWidth), argb); var oldBitmap = button.Image; button.Image = image.ToBitmap(); oldBitmap?.Dispose(); button.Tag = argb; }
protected override void UpdateVisualImageCore() { base.UpdateVisualImageCore(); VisualImage.Size = ImageBoxSize; ImagePainter.FillRect(VisualImage, new Rectangle(0, 0, VisualImage.Size.Width, VisualImage.Size.Height), BlackColorArgb); if (PagePrintSize.Width <= 0 || PagePrintSize.Height <= 0 || PrintSchemePagesCount.Width <= 0 || PrintSchemePagesCount.Height <= 0 || pageThumbnailSize.Width <= 0 || pageThumbnailSize.Height <= 0) { return; } var imageVisualPartSize = new Size(pageThumbnailSize.Width - PreviewPageBorder * 2, pageThumbnailSize.Height - PreviewPageBorder * 2); var pageWithMarginHeight = pageThumbnailSize.Height + PreviewPagesMargin; var startY = (VisualImage.Size.Height - pageWithMarginHeight * PrintSchemePagesCount.Height + PreviewPagesMargin) / 2; var pageWithMarginWidth = pageThumbnailSize.Width + PreviewPagesMargin; var palettePagesColumns = (PrintPalettePagesCount + PrintSchemePagesCount.Height - 1) / PrintSchemePagesCount.Height; var actualColumnsCount = PrintSchemePagesCount.Width + palettePagesColumns; var startX = (VisualImage.Size.Width - pageWithMarginWidth * actualColumnsCount) / 2; if (startX < 0) { startX = 0; } var schemePagesCount = PrintSchemePagesCount.Width * PrintSchemePagesCount.Height; for (int row = 0, y = startY, srcY = 0; row < PrintSchemePagesCount.Height; row++, y += pageWithMarginHeight, srcY += PageCellsSize.Height) { for (int col = 0, x = startX, srcX = 0; col < actualColumnsCount; col++, x += pageWithMarginWidth, srcX += PageCellsSize.Width) { var actualX = x; if (col >= PrintSchemePagesCount.Width) { actualX += PreviewPageBorder * 2; } if (col < PrintSchemePagesCount.Width && imageVisualPartSize.Width > 0 && imageVisualPartSize.Height > 0) { ImagePainter.FillRect(VisualImage, new Rectangle(actualX, y, pageThumbnailSize.Width, pageThumbnailSize.Height), WhiteColorArgb); var sourceCropRect = new Rectangle(srcX, srcY, PageCellsSize.Width, PageCellsSize.Height); if (sourceCropRect.RightExclusive > SourceImage.Size.Width) { sourceCropRect.Width = SourceImage.Size.Width - srcX; } if (sourceCropRect.BottomExclusive > SourceImage.Size.Height) { sourceCropRect.Height = SourceImage.Size.Height - srcY; } var croppedImage = ImageCropper.Crop(SourceImage, sourceCropRect); var zoomSize = new Size(sourceCropRect.Width * imageVisualPartSize.Width / PageCellsSize.Width, sourceCropRect.Height * imageVisualPartSize.Height / PageCellsSize.Height); var zoomedPartImage = new ImageResampler().Resample(croppedImage, zoomSize, ImageResampler.FilterType.Box); ImageCopier.Copy(zoomedPartImage, VisualImage, new Point(actualX + PreviewPageBorder, y + PreviewPageBorder)); PaintPageNumber(row * PrintSchemePagesCount.Width + col + 1, actualX, y); } else if (row * palettePagesColumns + col - PrintSchemePagesCount.Width + schemePagesCount < PagesCount) { ImagePainter.FillRect(VisualImage, new Rectangle(actualX, y, pageThumbnailSize.Width, pageThumbnailSize.Height), WhiteColorArgb); var lineX = actualX + PreviewPageBorder; var lineLength = pageThumbnailSize.Width / 2; var lastLineY = y + pageThumbnailSize.Height - PreviewPageBorder * 2; for (int lineY = y + PreviewPageBorder; lineY < lastLineY; lineY += 3) { ImagePainter.DrawHorizontalLine(VisualImage, lineX, lineY, lineLength, BlackColorArgb); } PaintPageNumber(schemePagesCount + row + (col - PrintSchemePagesCount.Width) * PrintSchemePagesCount.Height + 1, actualX, y); } } } }