From df6435a7a831e41a0282e9edc44e11104ad1e4ac Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 26 Jul 2016 23:42:59 +1000 Subject: [PATCH] Add Pad Former-commit-id: a998b9d94d6da006ff1381e93e2acb27a14546a8 Former-commit-id: e5c6fd1bbbf94f02f2702a09dfd16fba18662352 Former-commit-id: bf339f877e151c783b9d462b133429e9dc28aeb3 --- src/ImageProcessorCore/Samplers/Pad.cs | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/ImageProcessorCore/Samplers/Pad.cs diff --git a/src/ImageProcessorCore/Samplers/Pad.cs b/src/ImageProcessorCore/Samplers/Pad.cs new file mode 100644 index 0000000000..2bb6acc33b --- /dev/null +++ b/src/ImageProcessorCore/Samplers/Pad.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// ------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessorCore +{ + using Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Evenly pads an image to fit the new dimensions. + /// + /// The pixel format. + /// The packed format. long, float. + /// The source image to pad. + /// The new width. + /// The new height. + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image Pad(this Image source, int width, int height, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + ResizeOptions options = new ResizeOptions + { + Size = new Size(width, height), + Mode = ResizeMode.BoxPad, + Sampler = new NearestNeighborResampler() + }; + + return Resize(source, options, progressHandler); + } + } +}