mirror of https://github.com/SixLabors/ImageSharp
5 changed files with 62 additions and 22 deletions
@ -0,0 +1,27 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Extension methods that allow the addition of geometry calculating methods to the <see cref="IImageInfo"/> type
|
||||
|
/// </summary>
|
||||
|
public static class ImageInfoExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the bounds of the image.
|
||||
|
/// </summary>
|
||||
|
/// <param name="info">The image info</param>
|
||||
|
/// <returns>The <see cref="Size"/></returns>
|
||||
|
public static Size Size(this IImageInfo info) => new Size(info.Width, info.Height); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the bounds of the image.
|
||||
|
/// </summary>
|
||||
|
/// <param name="info">The image info</param>
|
||||
|
/// <returns>The <see cref="Rectangle"/></returns>
|
||||
|
public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.MetaData; |
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests |
||||
|
{ |
||||
|
public class ImageInfoTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void ImageInfoInitializesCorrectly() |
||||
|
{ |
||||
|
const int Width = 50; |
||||
|
const int Height = 60; |
||||
|
var size = new Size(Width, Height); |
||||
|
var rectangle = new Rectangle(0, 0, Width, Height); |
||||
|
var pixelType = new PixelTypeInfo(8); |
||||
|
var meta = new ImageMetaData(); |
||||
|
|
||||
|
var info = new ImageInfo(pixelType, Width, Height, meta); |
||||
|
|
||||
|
Assert.Equal(pixelType, info.PixelType); |
||||
|
Assert.Equal(Width, info.Width); |
||||
|
Assert.Equal(Height, info.Height); |
||||
|
Assert.Equal(size, info.Size()); |
||||
|
Assert.Equal(rectangle, info.Bounds()); |
||||
|
Assert.Equal(meta, info.MetaData); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue