How to Convert Image to Byte Array or Bitmap

This time I present code that can help you work with images (System.Drawing).
I showed how to convert Image to Byte Array and how to convert Image to Bitmap.

here is the code:

/// <summary>
/// Image Converter from Image to byte array
/// </summary>
/// <param name="img">Image</param>
/// <returns>byte</returns>
public static byte[] ImageToByte(Image img)
{
    ImageConverter converter = new ImageConverter();
    return (byte[])converter.ConvertTo(img, typeof(byte[]));
}

/// <summary>
/// Image Converter from Image to Bitmap
/// </summary>
/// <param name="img"></param>
/// <returns></returns>
public static Bitmap ImageToBitmap(Image img)
{
    ImageConverter converter = new ImageConverter();
    return (Bitmap)converter.ConvertTo(img, typeof(Bitmap));
}

Yours,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell