21 December, 2011
0 Comments
1 category
To convert a byte array to an image in C#, you can use the following code:
[TestMethod] public void Test() { byte[] bytes = new byte[100]; // Supply your bytes here. Image image = bytes.ToImage(); }
using System.Drawing; using System.IO; namespace Services.Extensions { /// <summary> /// Contains extensions methods to the byte[] type. /// </summary> public static class ByteArrayExtensions { /// <summary> /// Creates an images, based on the given bytes. /// </summary> /// <param name="image">The image.</param> /// <param name="byteArray">The byte array.</param> /// <returns></returns> public static Image ToImage(this byte[] byteArray) { return new Bitmap(new MemoryStream(byteArray)); } } }
Tags: C#
Category: Uncategorized