public void TestResampleWithCrop() { var sourceImage = new IndexedImage(); sourceImage.Size = new Size(43, 37); var random = new Random(); for (int i = 0; i < sourceImage.Pixels.Length; i++) { sourceImage.Pixels[i] = random.Next(); } var newSize = new Size(71, 59); var fullResampledImage = new ImageResampler().Resample(sourceImage, newSize, ImageResampler.FilterType.Lanczos3); Assert.AreEqual(newSize, fullResampledImage.Size); var frame = new Rectangle(7, 11, 23, 19); var croppedResampledImage = new ImageResampler().Resample(sourceImage, newSize, ImageResampler.FilterType.Lanczos3, frame); Assert.AreEqual(new Size(frame.Width, frame.Height), croppedResampledImage.Size); for (int y = 0; y < frame.Height; y++) { for (int x = 0; x < frame.Width; x++) { Assert.AreEqual(fullResampledImage.Pixels[(y + frame.Top) * fullResampledImage.Size.Width + (x + frame.Left)], croppedResampledImage.Pixels[y * croppedResampledImage.Size.Width + x]); } } }
public CrossPainter(int pixelHeight, IndexedImage whiteCrosses, Palette allColors) { Debug.Assert(whiteCrosses != null, "whiteCrosses should not be null"); PixelHeight = pixelHeight; WhiteCrosses = new ImageResampler().Resample(whiteCrosses, new Size(CrossesPerWhiteImageGridSize * pixelHeight, CrossesPerWhiteImageGridSize * pixelHeight), ImageResampler.FilterType.Lanczos3); InitializeCrossesForAllColors(allColors); }
void PaintPalettePage(IPainter painter, int page, int lineWidth, Rectangle margins) { var palettePage = page - PagesCount + PrintPalettePagesCount; var zoomedColorRowHeight = ColorRowHeight; var zoomedColorRowWidth = ColorRowSize.Width; var zoomedColorRowWidthWithSpacer = zoomedColorRowWidth + zoomedColorRowHeight; if (palettePage == 0) { var thumbnailMaxSize = zoomedColorRowHeight * 9; var sourceImageMaxSize = Math.Max(SourceImage.Size.Width, SourceImage.Size.Height); var thumbnailSize = new Size(SourceImage.Size.Width * thumbnailMaxSize / sourceImageMaxSize, SourceImage.Size.Height * thumbnailMaxSize / sourceImageMaxSize); var thumbnailImage = new ImageResampler().Resample(SourceImage, thumbnailSize, ImageResampler.FilterType.Box); painter.PaintImage(thumbnailImage, new Point(0, 0)); var infoX = thumbnailMaxSize + zoomedColorRowHeight; var infoY = 0; var textSize = zoomedColorRowHeight - lineWidth * 2; painter.PaintText(SourceImage.Description, new Point(infoX, infoY), textSize); infoY += zoomedColorRowHeight * 2; painter.PaintText(string.Format(Resources.PrintThreadsName, SourceImage.Palette.Name), new Point(infoX, infoY), textSize); var indexTextSize = textSize * 2 / 3; var indexCellSize = new Size(textSize, indexTextSize * 4 / 3); var startIndexX = margins.Width - PrintSchemePagesCount.Width * indexCellSize.Width; var indexY = 0; painter.PaintText(Resources.PrintPagesIndex, new Point(startIndexX, indexY), indexTextSize); indexY += textSize; for (int row = 0, index = 1; row < PrintSchemePagesCount.Height; row++, indexY += indexCellSize.Height) { for (int col = 0, indexX = startIndexX; col < PrintSchemePagesCount.Width; col++, index++, indexX += indexCellSize.Width) { painter.PaintText(index.ToString(), new Point(indexX, indexY), indexTextSize); } } } var startNo = palettePage * ColorRowsPerPage.Width * ColorRowsPerPage.Height; if (palettePage > 0) { startNo -= 20; } var startY = palettePage > 0 ? 0 : zoomedColorRowHeight * 10; var rowsPerPage = palettePage > 0 ? ColorRowsPerPage.Height : ColorRowsPerPage.Height - 10; for (int col = 0, x = 0; col < ColorRowsPerPage.Width; col++, x += zoomedColorRowWidthWithSpacer, startNo += rowsPerPage) { DrawColorsTable(painter, new Point(x, startY), OrderedColors, startNo, startNo + rowsPerPage, lineWidth, ColorRowSize, GridPainter.NumbersArgb, GridPainter.LineArgb, GridPainter.Line10Argb, ColorColumnNoWidth, ColorColumnSymbolWidth, ColorColumnCodeWidth, ColorColumnColorWidth); } }
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); } } } }
void InitializeRecentFilesButtons(ToolTip toolTip) { if (string.IsNullOrEmpty(Settings.Default.LastOpenFiles)) { var startupPath = Path.Combine(AppInfo.StartupPath, "Samples"); if (!string.IsNullOrEmpty(startupPath) && Directory.Exists(startupPath)) { var sampleFileNames = Directory.GetFiles(startupPath, "*.sa4").Take(10); Settings.Default.LastOpenFiles = string.Join(Settings.FilesSeparator.ToString(), sampleFileNames); Settings.Default.Save(); } } foreach (var fileName in Settings.Default.LastOpenFiles.Split(Settings.FilesSeparator)) { if (File.Exists(fileName)) { IndexedImage image; try { using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { image = ImageSerializer.LoadFromStream(stream); } } catch (IOException) { continue; } if (image != null && image.Size.Width > 0 && image.Size.Height > 0) { Bitmap bitmap; if (image.Size.Width > 200 || image.Size.Height > 200) { var maxLength = Math.Max(image.Size.Width, image.Size.Height); var newSize = new Size(image.Size.Width * 200 / maxLength, image.Size.Height * 200 / maxLength); bitmap = new ImageResampler().Resample(image, newSize, ImageResampler.FilterType.Box).ToBitmap(); } else { bitmap = image.ToBitmap(); } var imageButton = new FlatButton(); imageButton.Size = new System.Drawing.Size(250, 250); imageButton.Image = bitmap; imageButton.Text = Environment.NewLine + Path.GetFileNameWithoutExtension(fileName); imageButton.Tag = fileName; imageButton.TextAlign = ContentAlignment.BottomCenter; imageButton.ImageAlign = ContentAlignment.MiddleCenter; imageButton.FlatAppearance.BorderSize = 0; imageButton.Click += ImageButton_Click; var tooltip = fileName + Environment.NewLine + string.Format(Resources.ImageInfoTooltip, image.Size.Width, image.Size.Height, image.Palette.Count); toolTip.SetToolTip(imageButton, tooltip); panelLastOpenFiles.Controls.Add(imageButton); } } } }