How to check if jpeg image is empty

How to check if jpeg image is empty

Issue : How to check if jpeg image is empty.

Tips : To properly check if jpeg image is empty custom user processor can be added, which will check it.

Example :

using Aspose.Imaging;
using Aspose.Imaging.Brushes;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.FileFormats.Tiff;
using Aspose.Imaging.FileFormats.Tiff.Enums;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Sources;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;
using (RasterImage image = (RasterImage)Image.Load(dataDir + "template.jpg"))
{
if (!IsContentCorrect(image))
{
Console.WriteLine("Image is corrupted!");
}
else
Console.WriteLine("Image is OK!");
}
bool IsContentCorrect(RasterImage image)
{
try
{
image.LoadPartialArgb32Pixels(image.Bounds, new EmptyProcessor());
}
catch
{
return false;
}
return true;
}
class EmptyProcessor : IPartialArgb32PixelLoader
{
public void Process(Rectangle pixelsRectangle, int[] pixels, Point start, Point end)
{
// do nothing, just to enforce loading the pixels from jpeg
}
}