Every time I try to save a image in a jpeg format, I receive a "A generic error occurred in GDI+" Exception. The path of the output file is correct and the application has full permission on the folder where the file should be saved. Below the code that I used. The same code works great if I convert it to png:
public static bool XpsToImage(string inputFile, int page, int dpi)
{
var pages = new List<Bitmap>();
using (var xpsConverter = new Xps2Image(new MemoryStream(File.ReadAllBytes(inputFile))))
{
var image = xpsConverter.ToBitmap(new Parameters
{
Dpi = dpi,
ImageType = ImageType.Jpeg,
});
if (image == null)
return false;
pages.AddRange(image);
}
var outputfile = Path.GetDirectoryName(inputFile) + Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(inputFile) + "_preview.Jpeg";
try
{
if (page < pages.Count)
pages[page].Save(outputfile, ImageFormat.Jpeg);
}
catch (Exception ex)
{
LOGGER.Error("Cannot save image", ex);
return false;
}
return true;
}
Every time I try to save a image in a jpeg format, I receive a "A generic error occurred in GDI+" Exception. The path of the output file is correct and the application has full permission on the folder where the file should be saved. Below the code that I used. The same code works great if I convert it to png: