private void Form1_Load(object sender, EventArgs e) { Bitmap InputImage; Bitmap OutputImage; InputImage = (Bitmap)Image.FromFile(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Input\Image.jpg"); OutputImage = CreateBiTonalImage(InputImage, (byte.MaxValue * 3) / 2, Color.LightBlue, Color.ForestGreen); OutputImage.Save(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Output\CreateBiTonalImage.jpg"); }
private void Form1_Load(object sender, EventArgs e) { Bitmap InputImage; Bitmap OutputImage; InputImage = (Bitmap)Image.FromFile(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Input\Image.jpg"); OutputImage = GrayscaleTheImage(InputImage); OutputImage.Save(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Output\GrayscaleTheImage.jpg"); }
private void Form1_Load(object sender, EventArgs e) { Bitmap InputImage; Bitmap OutputImage; InputImage = (Bitmap)Image.FromFile(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Input\Image.jpg"); OutputImage = ApplyColorToImage(InputImage, Color.LawnGreen); OutputImage.Save(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Output\ApplyColorToImage.jpg"); }
static void Main(string[] args) { InitConfiguration(); CleanDir(pathTmp); CleanDir(pathRes); Log("Started. Scale: " + scale + " angleStep:" + angleStep + " lstSize: " + lstSize.Width + "x" + lstSize.Height); // Загрузка из PDF и масштабирование //InputHandling.ConvertPDFDirToScaledImg(pathSrc, pathTmp, scale); // Масштабирование Size scaledLstSize = new Size((int)(lstSize.Width * scale), (int)(lstSize.Height * scale)); InputHandling.ScaleWholeDirectory(pathSrc, pathTmp, scale); // Загрузка фигур Console.WriteLine("Starting process. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); List <Figure> data = Figure.LoadFigures(pathTmp, srcFigColor, angleStep, borderDistance, figAmount); data.Sort(Figure.CompareFiguresBySize); Figure.UpdIndexes(data); //Figure.DeleteWrongAngles(scaledLstSize.Width, scaledLstSize.Height, data); SolutionChecker.LoadFigures(data, pathPrologCode, scaleCoefs); Console.WriteLine("Figure loading finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); Log("Loaded Figs."); // Поиск решения Console.WriteLine("Starting result finding. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); var preDefArr = SolutionChecker.FindAnAnswer(data, scaledLstSize.Width, scaledLstSize.Height, pathPrologCode, scaleCoefs); var result = SolutionChecker.PlacePreDefinedArrangement(preDefArr, scaledLstSize.Width, scaledLstSize.Height, scaleCoefs); if (result == null) { Log("Prolog finished. No answer."); } else { Log("Prolog finished. Answer was found."); // Отображение решения Console.WriteLine("Starting visualization. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); OutputImage.SaveResult(data, preDefArr, result, pathRes, scaledLstSize.Width, scaledLstSize.Height); OutputText.SaveResult(preDefArr, data, result, pathRes + "result.txt"); } Console.WriteLine("Process finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); Log("Finished."); Console.ReadLine(); }
private void button_FindAnswer_Click(object sender, EventArgs e) { if (choseenFigsPath.Count == 0) { MessageBox.Show("Не выбраны детали"); return; } InitConfiguration(); CleanDir(pathTmp); CleanDir(pathRes); // Масштабирование Size scaledLstSize = new Size((int)(lstSize.Width * scale), (int)(lstSize.Height * scale)); InputHandling.ScaleAllFigs(choseenFigsPath, pathTmp, scale); // Загрузка фигур Console.WriteLine("Starting process. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); List <Figure> data = Figure.LoadFigures(pathTmp, srcFigColor, angleStep, borderDistance, figAmount); data.Sort(Figure.CompareFiguresBySize); Figure.UpdIndexes(data); Figure.DeleteWrongAngles(scaledLstSize.Width, scaledLstSize.Height, data); SolutionChecker.LoadFigures(data, pathPrologCode, scaleCoefs); Console.WriteLine("Figure loading finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); // Поиск решения Console.WriteLine("Starting result finding. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); var preDefArr = SolutionChecker.FindAnAnswer(data, scaledLstSize.Width, scaledLstSize.Height, pathPrologCode, scaleCoefs); var result = SolutionChecker.PlacePreDefinedArrangement(preDefArr, scaledLstSize.Width, scaledLstSize.Height, scaleCoefs); if (result == null) { MessageBox.Show("Prolog finished. No answer."); } else { MessageBox.Show("Prolog finished. Answer was found."); // Отображение решения Console.WriteLine("Starting visualization. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); OutputImage.SaveResult(data, preDefArr, result, pathRes, scaledLstSize.Width, scaledLstSize.Height); OutputText.SaveResult(preDefArr, data, result, pathRes + "result.txt"); } Console.WriteLine("Process finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); Console.ReadLine(); }
public void SetOutputImagesFullDirectory(VideoCollection videoCollection) { Barcode_Standard = new OutputImage { OutputFilename = $"{videoCollection.Config.FilenameWithoutExtension}_{OutputWidth}_{OutputHeight}.jpg" }; Barcode_1px = new OutputImage { OutputFilename = $"{videoCollection.Config.FilenameWithoutExtension}_1px_{OutputWidth}_{OutputHeight}.jpg" }; Barcode_Standard.SetFullOutputFile(videoCollection); Barcode_1px.SetFullOutputFile(videoCollection); }
public BarcodeConfig(int duration, string filenameWithoutExtension) { OutputWidth = duration; Barcode_Standard = new OutputImage { OutputFilename = $"{filenameWithoutExtension}_{OutputWidth}_{OutputHeight}.jpg" }; Barcode_1px = new OutputImage { OutputFilename = $"{filenameWithoutExtension}_1px_{OutputWidth}_{OutputHeight}.jpg" }; CreateOnePixelBarcode = true; }
public void SetsCustomBackground() { var config = GetConfiguration(); var generator = new ImageResizeGenerator(config); var image = new OutputImage { Height = 0, Width = 0, InputFile = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"), OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"), OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"), RequiresBackgroundColor = true, Scale = 1, ShouldBeVisible = true, WatermarkFilePath = null, BackgroundColor = "#8A2BE2" }; generator.ProcessImage(image); using var inputImage = Image.Load(image.InputFile); using var outputImage = Image.Load(image.OutputFile); using var inputClone = inputImage.CloneAs <Rgba32>(); using var outputClone = outputImage.CloneAs <Rgba32>(); var comparedTransparentPixel = false; for (var y = 0; y < inputImage.Height; ++y) { var inputPixelRowSpan = inputClone.GetPixelRowSpan(y); var outputPixelRowSpan = outputClone.GetPixelRowSpan(y); for (var x = 0; x < inputImage.Width; ++x) { var startingPixel = inputPixelRowSpan[x]; if (startingPixel.A == 0) { comparedTransparentPixel = true; var pixel = outputPixelRowSpan[x]; Assert.Equal(138, pixel.R); Assert.Equal(43, pixel.G); Assert.Equal(226, pixel.B); Assert.Equal(255, pixel.A); } } } Assert.True(comparedTransparentPixel); }
private void DrawOutputImage() { for (int col = 0; col < numCols; col++) { for (int row = 0; row < numRows; row++) { Point insertPosition = new Point(borderThicknessW + col * (CropArea.Width + borderThicknessW), borderThicknessH + row * (CropArea.Height + borderThicknessH)); OutputImage.Mutate(i => i .DrawImage(CroppedImage, 1, insertPosition)); } } if (OutputImageRotationDegrees > 0.0) { OutputImage.Mutate(i => i.Rotate(OutputImageRotationDegrees)); } }
public void AppliesWatermark(string inputImageName, string watermarkImage) { var config = GetConfiguration(); var generator = new ImageResizeGenerator(config); var image = new OutputImage { Height = 0, Width = 0, InputFile = Path.Combine(TestConstants.WatermarkImageDirectory, $"{inputImageName}.png"), OutputFile = Path.Combine($"{config.IntermediateOutputPath}-{inputImageName}-{watermarkImage}", $"{inputImageName}.png"), OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", $"{inputImageName}.png"), RequiresBackgroundColor = false, Scale = 1, ShouldBeVisible = true, Watermark = new WatermarkConfiguration { SourceFile = Path.Combine(TestConstants.WatermarkImageDirectory, $"{watermarkImage}.png") } }; generator.ProcessImage(image); using var inputImage = Image.Load(image.InputFile); using var outputImage = Image.Load(image.OutputFile); using var inputClone = inputImage.CloneAs <Rgba32>(); using var outputClone = outputImage.CloneAs <Rgba32>(); bool appliedWatermark; for (var y = 0; y < inputImage.Height; ++y) { var inputPixelRowSpan = inputClone.GetPixelRowSpan(y); var outputPixelRowSpan = outputClone.GetPixelRowSpan(y); for (var x = 0; x < inputImage.Width; ++x) { appliedWatermark = inputPixelRowSpan[x] == outputPixelRowSpan[x]; if (appliedWatermark) { return; } } } _testOutputHelper.WriteLine("All pixels are the same in the Input and Output Images"); Assert.True(false); }
internal override void ExecuteInternal(IBuildConfiguration config) { GeneratedImages = Array.Empty <ITaskItem>(); var images = Images.Select(x => OutputImage.FromTaskItem(x)); if (!images.Any()) { return; } var generator = new ImageResizeGenerator(this) { OutputImages = images, }; generator.Execute(); GeneratedImages = generator.Outputs.Select(x => x.ToTaskItem()).ToArray(); }
public void SetsDefaultBackground() { var config = GetConfiguration(); var generator = new ImageResizeGenerator(config); var image = new OutputImage { Height = 0, Width = 0, InputFile = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"), OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"), OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"), RequiresBackgroundColor = true, Scale = 1, ShouldBeVisible = true, Watermark = null }; generator.ProcessImage(image); VerifyImageContents(image); }
public void AppliesTextBanner(string text) { var config = GetConfiguration(); var generator = new ImageResizeGenerator(config); var image = new OutputImage { Height = 0, Width = 0, InputFile = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"), OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"), OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"), RequiresBackgroundColor = true, Scale = .5, ShouldBeVisible = true, Watermark = new WatermarkConfiguration { Text = text } }; generator.ProcessImage(image); }
public void ConvertedImageUsesDefaultValues() { var outputImage = new OutputImage { OutputFile = "Sample.png", Watermark = new WatermarkConfiguration { Text = "Hello World", } }; var taskItem = outputImage.ToTaskItem(); var convertedImage = OutputImage.FromTaskItem(taskItem); Assert.NotNull(convertedImage.Watermark); Assert.Equal(outputImage.Watermark.Text, convertedImage.Watermark.Text); Assert.Equal("White", convertedImage.Watermark.TextColor); Assert.Equal(new[] { "Red", "OrangeRed" }, convertedImage.Watermark.Colors); Assert.Equal("Arial", convertedImage.Watermark.FontFamily); Assert.Equal(WatermarkPosition.BottomRight, convertedImage.Watermark.Position); Assert.Equal(Constants.DefaultOpacity, convertedImage.Watermark.Opacity); }
/// <summary> /// Rescales the start/end image from the originals to the keep performance at preview-time high. /// Then recreates the output image with appropriate size corresponding to scaled StartImage and EndImage /// </summary> private void AdaptInputOutputImages() { if (_originalStartImage == null || _originalEndImage == null) { return; } StartImage.Source = _originalStartImage; StartImage.UpdateLayout(); StartImage.Source = ImageUtilities.CreateResizedImage(_originalStartImage, (int)(StartImage.ActualWidth), (int)(StartImage.ActualHeight)); EndImage.Source = _originalEndImage; EndImage.UpdateLayout(); EndImage.Source = ImageUtilities.CreateResizedImage(_originalEndImage, (int)(EndImage.ActualWidth), (int)(EndImage.ActualHeight)); // create output image int width = (int)Math.Max(StartImage.ActualWidth, EndImage.ActualWidth); int height = (int)Math.Max(StartImage.ActualHeight, EndImage.ActualHeight); OutputImage.Source = new WriteableBitmap(width, height, 0.0f, 0.0f, PixelFormats.Bgra32, null); OutputImage.UpdateLayout(); StartImage.UpdateLayout(); EndImage.UpdateLayout(); // setup for morphing _morphingAlgorithm.SetStartImage(StartImage.Source as BitmapSource); _morphingAlgorithm.SetEndImage(EndImage.Source as BitmapSource); // upate output if (!_animationPlayer.IsEnabled) { UpdateOutputImageContent(); } // update marker view UpdateMarkerCanvases(); }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var timeout = TimeoutMS.Get(context); var inputImage = InputImage.Get(context); var positionX = PositionX.Get(context); var positionY = PositionY.Get(context); var width = Width.Get(context); var height = Height.Get(context); var blur = Blur.Get(context); var blurAmount = BlurAmount.Get(context); // Set a timeout on the execution var task = ExecuteWithTimeout(context, cancellationToken); if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task) { throw new TimeoutException(Resources.Timeout_Error); } Image returnImage; // Check if activity should blur or hide part of the image if (blur) { // Convert image to bytestream ImageConverter _imageConverter = new ImageConverter(); byte[] imageByteStream = (byte[])_imageConverter.ConvertTo(inputImage, typeof(byte[])); // Create image from bytestream for MagickImage use var magickimage = new MagickImage(imageByteStream); // Blur part of image magickimage.RegionMask(new MagickGeometry(positionX, positionY, width, height)); magickimage.GaussianBlur(blurAmount, 25); magickimage.RemoveRegionMask(); // Convert MagickInmage to Bytestream var imageBytesOut = magickimage.ToByteArray(); MemoryStream ms = new MemoryStream(imageBytesOut); // Create return image from bytestream returnImage = Image.FromStream(ms); } else { // Create graphics context with returnImage returnImage = inputImage; using (Graphics g = Graphics.FromImage(returnImage)) { // Define brush and rectangle SolidBrush blackBrush = new SolidBrush(Color.Black); Rectangle rect = new Rectangle(positionX, positionY, width, height); // Fill rectangle g.FillRectangle(blackBrush, rect); // Cleanup g.Dispose(); } } // Outputs return((ctx) => { OutputImage.Set(ctx, returnImage); }); }