namespace VAL { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.IO; /// <summary> /// Helper class to provide functionality for transforming the byte array data stored /// in SQL Server into an Image file for use in icons /// </summary> internal static class IconConverter { /// <summary> /// Creates an Image object from a binary array /// </summary> /// <param name="byteArray"></param> /// <returns></returns> public static Image ImageFromByteArray(byte[] byteArray) { if (byteArray == null || byteArray.Length == 0) return null; using (var ms = new System.IO.MemoryStream(byteArray)) { return Image.FromStream(ms); } } public static byte[] ByteArrayFromImage(Icon icon) { return ByteArrayFromImage(icon.ToBitmap()); } /// <summary> /// Creates a binary array from an Image object /// </summary> /// <param name="image"></param> /// <returns></returns> public static byte[] ByteArrayFromImage(Image image) { var converter = new ImageConverter(); return (byte[])converter.ConvertTo(image, typeof(byte[])); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)