Utililty function to convert file extension to ImageFileType enum

Is there any method to find ImageFileType from file extension?

Hi there,

Thanks for your inquriy. You may use may use Aspose.Imaging to detect image file format and use ImageFileType accordingly. However if there is any difference in your requirements and my understanding then please share some more details along with sample code here, so we will look into it and will guide you accordingly.

Image file format detection using Aspose.Imaging:

int imageType = (int)Aspose.Imaging.Image.GetFileFormat(“Test.PNG”);

String image = null;

switch (imageType) {

case 0: image = “Undefined”;

break;

case 1: image = “Custom”;

break;

case 2: image = “BMP”;

break;

case 4: image = “GIF”;

break;

case 8: image = “JPEG”;

break;

case 16: image = “PNG”;

break;

case 32: image = “TIFF”;

break;

case 64: image = “PSD”;

break;

case 128: image = “DXF”;

break;

case 256: image = “DWG”;

break;

case 512: image = “Jpeg2000”;

break;

case 1024: image = “Djvu”;

break;

}

Console.Out.WriteLine(image);

Please feel free to contact us for any further assistance.

Best Regards,

I use Aspose.Pdf and I can't use Aspose.Imaging in my project.
I have array of images with different type and I want to convert this images to separate pdf in a loop.
I use bellow sample code to do this, But I don't know how to get Aspose.Pdf.Generator.ImageFileType from file extensions.

How to Convert an Image to PDF



Hi Freydoon,


Thanks for sharing the details.

The above stated approach is an old legacy approach of Image to PDF conversion where its required to specify the type of input image. However we recommend using new Document Object Model of Aspose.Pdf namespace for Image to PDF conversion, which do not require the image type but in fact it automatically determines the image type and performs the conversion. For more information, please visit Convert an Image to PDF

In case you encounter any issue, please share the input files, so that we can further test the scenario in our environment.

Thanks for the prompt reply.

This was exactly what I needed.

Best regards.

Hi Freydoon,


Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel free to contact.