We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Detect empty jpg image

Can Image.net help me to identify whether an jpg image is an empty image or not? customer might scan the wrong side of the document and I need to aware it. if can,
can you show me how in C# thanks.

Hi Markwe,

Thank you for your inquiry.

Please, note that one possible solution to detect that the image file is an empty image could be by parsing each and every pixel of the image and check the RGB values. If all (or some percent of) pixel values i.e. RGB correspond to white color (R: 255, G: 255, B: 255) that means the image is a blank image. However, if the image is a scanned image there could be a possibility of minor black color spots. In this case, the above mentioned solution may require further tweaking/checks to determine the percentage of the colored pixels on the image, based on which you may decide if the image is blank or have contents on it.

We are attaching the sample code for your kind reference.

//Initialize variables to hold width & height values
int width = 0;
int height = 0;

//Initialize an array of type Color to hold the pixel data
Aspose.Imaging.Color[] pixels = null;
//Create an instance of RasterImage and load JPG image
using (Aspose.Imaging.RasterImage raster = (Aspose.Imaging.RasterImage) Aspose.Imaging.Image.Load(@"C:\blank_image.jpg"))
//Store the width & height in variables for later use
width = raster.Width;
height = raster.Height;
//Load the pixels of RasterImage into the array of type Color
pixels = raster.LoadPixels(new Aspose.Imaging.Rectangle(0, 0, width, height));
//Loop over the Array and get the pixel index and RGB values
for (int index = 0; index < pixels.Length; index++)
Console.WriteLine("PIXEL INDEX : " + index.ToString());
Console.WriteLine("R : " + pixels[index].R);
Console.WriteLine("G : " + pixels[index].G);
Console.WriteLine("B : " + pixels[index].B);

Hope the above information helps. Please feel free to write us back in case you have further concerns or questions for us.