public void ResizeWidthAndHeight() { int width = 50; int height = 100; this.operations.Resize(width, height); ResizeProcessor resizeProcessor = this.Verify <ResizeProcessor>(); Assert.Equal(width, resizeProcessor.DestinationWidth); Assert.Equal(height, resizeProcessor.DestinationHeight); }
public void ResizeWidthAndHeight() { int width = 50; int height = 100; this.operations.Resize(width, height); ResizeProcessor <Rgba32> resizeProcessor = this.Verify <ResizeProcessor <Rgba32> >(); Assert.Equal(width, resizeProcessor.Width); Assert.Equal(height, resizeProcessor.Height); }
public void PadWidthHeightResizeProcessorWithCorrectOptionsSet() { int width = 500; int height = 565; IResampler sampler = KnownResamplers.NearestNeighbor; this.operations.Pad(width, height); ResizeProcessor resizeProcessor = this.Verify <ResizeProcessor>(); Assert.Equal(width, resizeProcessor.DestinationWidth); Assert.Equal(height, resizeProcessor.DestinationHeight); Assert.Equal(sampler, resizeProcessor.Sampler); }
public void ResizeWidthAndHeightAndSampler() { int width = 50; int height = 100; IResampler sampler = KnownResamplers.Lanczos3; this.operations.Resize(width, height, sampler); ResizeProcessor resizeProcessor = this.Verify <ResizeProcessor>(); Assert.Equal(width, resizeProcessor.DestinationWidth); Assert.Equal(height, resizeProcessor.DestinationHeight); Assert.Equal(sampler, resizeProcessor.Sampler); }
public void ResizeWidthAndHeightAndSampler() { int width = 50; int height = 100; IResampler sampler = ResampleMode.Lanczos3; this.operations.Resize(width, height, sampler); ResizeProcessor <Rgba32> resizeProcessor = this.Verify <ResizeProcessor <Rgba32> >(); Assert.Equal(width, resizeProcessor.Width); Assert.Equal(height, resizeProcessor.Height); Assert.Equal(sampler, resizeProcessor.Sampler); }
public void PadWidthHeightResizeProcessorWithCorrectOptionsSet() { int width = 500; int height = 565; IResampler sampler = ResampleMode.NearestNeighbor; this.operations.Pad(width, height); ResizeProcessor <Rgba32> resizeProcessor = this.Verify <ResizeProcessor <Rgba32> >(); Assert.Equal(width, resizeProcessor.Width); Assert.Equal(height, resizeProcessor.Height); Assert.Equal(sampler, resizeProcessor.Sampler); }
public void ResizeWidthAndHeightAndSamplerAndCompand() { int width = 50; int height = 100; IResampler sampler = KnownResamplers.Lanczos3; bool compand = true; // ReSharper disable once ConditionIsAlwaysTrueOrFalse this.operations.Resize(width, height, sampler, compand); ResizeProcessor resizeProcessor = this.Verify <ResizeProcessor>(); Assert.Equal(width, resizeProcessor.DestinationWidth); Assert.Equal(height, resizeProcessor.DestinationHeight); Assert.Equal(sampler, resizeProcessor.Sampler); Assert.Equal(compand, resizeProcessor.Compand); }
/// <summary> /// Resizes an image to the given width and height with the given sampler and /// source rectangle. /// </summary> /// <typeparam name="T">The pixel format.</typeparam> /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam> /// <param name="source">The image to resize.</param> /// <param name="width">The target image width.</param> /// <param name="height">The target image height.</param> /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param> /// <param name="sourceRectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// </param> /// <param name="targetRectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the target image object to draw to. /// </param> /// <param name="compand">Whether to compress and expand the image color-space to gamma correct the image during processing.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <returns>The <see cref="Image{T,TP}"/></returns> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> public static Image <T, TP> Resize <T, TP>(this Image <T, TP> source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false, ProgressEventHandler progressHandler = null) where T : IPackedVector <TP> where TP : struct { if (width == 0 && height > 0) { width = source.Width * height / source.Height; targetRectangle.Width = width; } if (height == 0 && width > 0) { height = source.Height * width / source.Width; targetRectangle.Height = height; } Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); ResamplingWeightedProcessor <T, TP> processor; if (compand) { processor = new CompandingResizeProcessor <T, TP>(sampler); } else { processor = new ResizeProcessor <T, TP>(sampler); } processor.OnProgress += progressHandler; try { return(source.Process(width, height, sourceRectangle, targetRectangle, processor)); } finally { processor.OnProgress -= progressHandler; } }
// [Fact] public void PrintWeightsData() { ResizeProcessor <Rgba32> proc = new ResizeProcessor <Rgba32>(new BicubicResampler(), 200, 200); ResamplingWeightedProcessor <Rgba32> .WeightsBuffer weights = proc.PrecomputeWeights(200, 500); StringBuilder bld = new StringBuilder(); foreach (ResamplingWeightedProcessor <Rgba32> .WeightsWindow window in weights.Weights) { for (int i = 0; i < window.Length; i++) { float value = window.Span[i]; bld.Append(value); bld.Append("| "); } bld.AppendLine(); } File.WriteAllText("BicubicWeights.MD", bld.ToString()); //this.Output.WriteLine(bld.ToString()); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Expected path argument! \n Usage DemotivatorGenerator.exe <path-to-pic> <upper-text> <lower-text> <amount>"); return; } var path = args[0]; var amount = args.Length > 3 ? int.Parse(args[3]) : 1; var upperText = args.Length > 1 ? args[1] : "ЭТО ДИМАТИВАТОР"; var lowerText = args.Length > 2 ? args[2] : "нет"; var bmp = Image.FromFile(path); if (bmp.Width < 200 || bmp.Height < 200) { var lowerSide = bmp.Width < bmp.Height ? bmp.Width : bmp.Height; var multiplier = 300 / lowerSide; var resizer = new ResizeProcessor(bmp.Width * multiplier, bmp.Height * multiplier); bmp = resizer.Process((Bitmap)bmp); } var processor = new DemotivatorProcessor(upperText, lowerText); var resizeProc = new ResizeProcessor(0, 0); Console.WriteLine(bmp.PixelFormat); var procImg = processor.Process((Bitmap)bmp); for (var i = 1; i < amount; i++) { procImg = processor.Process(procImg); resizeProc.SetSize(procImg.Width * 5 / 6, procImg.Height * 5 / 6); procImg = resizeProc.Process(procImg); } procImg.Save("sosat.jpg"); }