From 196cdf8b782800493a0b72b33665acf18b2f7810 Mon Sep 17 00:00:00 2001 From: dirk Date: Sun, 30 Oct 2016 11:24:52 +0100 Subject: [PATCH] Added method to IImageBase that can be used to initialize the pixels of an image. --- src/ImageSharp/Image/IImageBase.cs | 10 ++++++++++ src/ImageSharp/Image/ImageBase.cs | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Image/IImageBase.cs b/src/ImageSharp/Image/IImageBase.cs index fdd82099f..3168b4bb5 100644 --- a/src/ImageSharp/Image/IImageBase.cs +++ b/src/ImageSharp/Image/IImageBase.cs @@ -19,6 +19,16 @@ namespace ImageSharp /// TColor[] Pixels { get; } + /// + /// Sets the size of the pixel array of the image to the given width and height. + /// + /// The new width of the image. Must be greater than zero. + /// The new height of the image. Must be greater than zero. + /// + /// Thrown if either or are less than or equal to 0. + /// + void InitPixels(int width, int height); + /// /// Sets the pixel array of the image to the given value. /// diff --git a/src/ImageSharp/Image/ImageBase.cs b/src/ImageSharp/Image/ImageBase.cs index 10c8c114a..0bc527519 100644 --- a/src/ImageSharp/Image/ImageBase.cs +++ b/src/ImageSharp/Image/ImageBase.cs @@ -41,12 +41,7 @@ namespace ImageSharp /// protected ImageBase(int width, int height) { - Guard.MustBeGreaterThan(width, 0, nameof(width)); - Guard.MustBeGreaterThan(height, 0, nameof(height)); - - this.Width = width; - this.Height = height; - this.pixelBuffer = new TColor[width * height]; + this.InitPixels(width, height); } /// @@ -102,6 +97,17 @@ namespace ImageSharp /// public int FrameDelay { get; set; } + /// + public void InitPixels(int width, int height) + { + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + this.Width = width; + this.Height = height; + this.pixelBuffer = new TColor[width * height]; + } + /// public void SetPixels(int width, int height, TColor[] pixels) {