How to determine if an image is partially damaged? WITH#

I have the original bytes for the image. I use the following for code to determine if an image is corrupt or not.

public bool IsValidGDIPlusImage(byte[] imageData)
{
    try
    {
        using (var ms = new MemoryStream(imageData))
        {
            using (var bmp = new Bitmap(ms))
            {
            }
        }
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}

If the image is completely damaged, the above code works fine, but what if I have an image that is partially damaged? Like jpeg below

enter image description here

How to determine if an image is partially damaged?

The original image, under which there is a simple image 300 × 300 in size with a diagonal line from the center.

enter image description here Any guidance is much appreciated. Thanks

+5
source share

All Articles