Mega Code Archive

 
Categories / C# / 2D Graphics
 

Saves the image to a bytes array Used to store an image into DB

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing; using System.IO; using System.Drawing.Imaging; namespace Phaeton.Helpers.ImageUtilities {     /// <summary>     /// General routines for image manipulating.     /// </summary>     public static class ImageHelper     {         /// <summary>         /// Saves the image to a bytes array. Used to store an image into DB.         /// </summary>         /// <param name="image">Image.</param>         /// <param name="imageFormat">Format to save the image with.</param>         /// <returns>Byte array that represents the specified image.</returns>         public static byte[] GetBytes(Image image, ImageFormat imageFormat)         {             using (MemoryStream stream = new MemoryStream())             {                 image.Save(stream, imageFormat);                 byte[] bytes = new byte[stream.Length];                 stream.Position = 0;                 stream.Read(bytes, 0, bytes.Length);                 return bytes;             }         }     } }