diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
index 9dbfacbba..8c03d64e9 100644
--- a/src/ImageSharp/Image.cs
+++ b/src/ImageSharp/Image.cs
@@ -45,6 +45,18 @@ namespace ImageSharp
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes)
+ : base(bytes)
+ {
+ }
+
///
/// Initializes a new instance of the class
/// by making a copy from another image.
diff --git a/src/ImageSharp/Image/Image.cs b/src/ImageSharp/Image/Image.cs
index 6dfd1c6db..cec75102a 100644
--- a/src/ImageSharp/Image/Image.cs
+++ b/src/ImageSharp/Image/Image.cs
@@ -72,6 +72,23 @@ namespace ImageSharp
this.Load(stream);
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes)
+ {
+ Guard.NotNull(bytes, nameof(bytes));
+
+ using (MemoryStream stream = new MemoryStream(bytes, false))
+ {
+ this.Load(stream);
+ }
+ }
+
///
/// Initializes a new instance of the class
/// by making a copy from another image.
diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs
new file mode 100644
index 000000000..2dd73a0b5
--- /dev/null
+++ b/tests/ImageSharp.Tests/Image/ImageTests.cs
@@ -0,0 +1,32 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Tests
+{
+ using System;
+
+ using Xunit;
+
+ ///
+ /// Tests the class.
+ ///
+ public class ImageTests
+ {
+ [Fact]
+ public void ConstructorByteArray()
+ {
+ Assert.Throws(() =>
+ {
+ new Image((byte[])null);
+ });
+
+ TestFile file = TestImages.Bmp.Car;
+ var image = new Image(file.Bytes);
+
+ Assert.Equal(600, image.Width);
+ Assert.Equal(450, image.Height);
+ }
+ }
+}
diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs
index f7e7f8517..89a724191 100644
--- a/tests/ImageSharp.Tests/TestFile.cs
+++ b/tests/ImageSharp.Tests/TestFile.cs
@@ -16,12 +16,12 @@ namespace ImageSharp.Tests
{
this.file = file;
- using (FileStream stream = File.OpenRead(file))
- {
- this.image = new Image(stream);
- }
+ this.Bytes = File.ReadAllBytes(file);
+ this.image = new Image(this.Bytes);
}
+ public byte[] Bytes { get; }
+
public string FileName
{
get