This project has moved. For the latest updates, please go here.

System.Drawing.Image Extension Methods

Image.Cut Method

An Image extension method that cuts an image.

Syntax

Image Cut(Image @this,int width,int height,int x,int y)

Parameters

@this
The @this to act on.
width
The width.
height
The height.
x
The x coordinate.
y
The y coordinate.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Drawing;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Drawing_Image_Cut
     {
         [TestMethod]
         public void Cut()
         {
             // Type
             var @this = new Bitmap(2, 2);
 
             // Examples
             Image value = @this.Cut(1, 1, 1, 1); // Return an Image(1, 1)
 
             // Unit Test
             Assert.AreEqual(1, value.Width);
             Assert.AreEqual(1, value.Height);
         }
     }
 }
                

Image.Scale Method

An Image extension method that scales an image to the specific ratio.

Syntax

Image Scale(Image @this,double ratio)

Parameters

@this
The @this to act on.
ratio
The ratio.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Drawing;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Drawing_Image_Scale
     {
         [TestMethod]
         public void Scale()
         {
             // Type
             var @this = new Bitmap(1, 1);
 
             // Examples
             Image value1 = @this.Scale(2); // return an Image(2, 2);
             Image value2 = @this.Scale(2, 2); // return an Image(2, 2);
 
             // Unit Test
             Assert.AreEqual(2, value1.Width);
             Assert.AreEqual(2, value1.Height);
             Assert.AreEqual(2, value2.Width);
             Assert.AreEqual(2, value2.Height);
         }
     }
 }
                

Image.Scale Method

An Image extension method that scales an image to a specific with and height.

Syntax

Image Scale(Image @this,int width,int height)

Parameters

@this
The @this to act on.
width
The width.
height
The height.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Drawing;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Drawing_Image_Scale
     {
         [TestMethod]
         public void Scale()
         {
             // Type
             var @this = new Bitmap(1, 1);
 
             // Examples
             Image value1 = @this.Scale(2); // return an Image(2, 2);
             Image value2 = @this.Scale(2, 2); // return an Image(2, 2);
 
             // Unit Test
             Assert.AreEqual(2, value1.Width);
             Assert.AreEqual(2, value1.Height);
             Assert.AreEqual(2, value2.Width);
             Assert.AreEqual(2, value2.Height);
         }
     }
 }
                

Last edited Nov 23, 2013 at 6:54 PM by Jonathan_Magnan, version 1