Your code is making a lot of assumptions about what constitutes an image in a PDF. PDF images aren't images in the standard sense; instead, they are just arrays of colour values. Why not use PdfImageObject instead? This is designed to read the PDF "images" and cope with that. You can get the underlying image from this using the GetDrawingImage method. An example of doing this might look something like this:
public static Image GetImage(this PdfObject pdfObject)
{
PdfStream pdfStream = pdfObject as PdfStream;
if (stream == null) return null;
PdfObject streamType = stream.Get(PdfName.SUBTYPE);
if (streamtype == null) return null;
if (streamType.ToString() == PdfName.IMAGE.ToString())
{
PdfImageObject image = new PdfImageObject((PRStream)stream);
return image?.GetDrawingImage();
}
return null;
}