We implemented a validation to prevent users from uploading PNG files with transparency using this code snippet:
using (PngImage image = (PngImage)Aspose.Imaging.Image.Load(filePath))
float opacity = image.ImageOpacity;
if (opacity != 1)
But, we are having issues with some PNG files. Here is one file: Upload Error.jpg (10.0 KB)
It’s throwing the following exception:
Unable to cast object of type ‘Aspose.Imaging.FileFormats.Jpeg.JpegImage’ to type ‘Aspose.Imaging.FileFormats.Png.PngImage’.
How can we prevent this from happening? What else are we missing? Should we include some additional validations?
Please let us know and include some code snippets. Thanks!