Tuesday, June 3, 2014

How to check if a byte array is a valid image?

public static bool IsValidImage(byte[] bytes)
{
    try
    {
        using (MemoryStream ms = new MemoryStream(bytes))
            System.Drawing.Image.FromStream(ms);
    }
    catch (ArgumentException)
    {
        return false;
    }
    return true;
}

No comments:

Post a Comment