CreateGdPictureImageFromFile returning 0, ability to get more detail on UnknownImageFormat status
Posted: Fri Sep 23, 2022 2:37 am
I have an application that is retrieving an image or pdf from an API. Once the file is saved, the file type is checked and the desired action is to have a jpeg thumbnail and the file is a tiff it calls the following code:
Often enough I am getting 0 returned from CreateGdPictureImageFromFile and GetStat() outputs UnknownImageFormat to the error that is being thrown. I can take the offending files and put them in the GDPicture sample C# FileConverter and the file will successfully convert as it does in an application with a form with only a submit button and the file path statically coded to pass just the filename to the above code. There are tiff files of different compressions that fail and those same compressions will other times be successful and convert without issue.
Is there a way to get more detail of what CreateGdPictureImageFromFile is not liking and why it is getting an UnknownImageFormat? I am using 14.1.0.184 from NuGet.
Thanks for any help.
Code: Select all
public static int ConvertTiffToJpeg(string fileName, int maxpagenum = 9999)
{
try
{
int page_count = 0;
int m_SrcImageID = 0;
GdPictureImaging oGdPictureImaging = new GdPictureImaging(); // GdPictureImaging object for loading and saving images
oGdPictureImaging.ReleaseGdPictureImage(m_SrcImageID);
string m_Name = Path.GetFileNameWithoutExtension(fileName); //Variable to hold input and output file name
m_SrcImageID = oGdPictureImaging.CreateGdPictureImageFromFile(fileName);
if (m_SrcImageID == 0)
{
throw new System.SystemException("Failed attempting to convert TIFF [" + fileName + "] to JPEG, err: " + oGdPictureImaging.GetStat().ToString());
}
string m_DestinationFolder = Path.GetDirectoryName(fileName); //Path of Folder to be saved in
int NumberOfPages = oGdPictureImaging.GetPageCount(m_SrcImageID);
for (int i = 1; i <= NumberOfPages && i <= maxpagenum; i++)
{
oGdPictureImaging.TiffSelectPage(m_SrcImageID, i);
string m_DestinationPath = Path.Combine(m_DestinationFolder, m_Name + "_" + i.ToString() + ".jpg"); //Full Path of Destination
GdPictureStatus m_Status = oGdPictureImaging.SaveAsJPEG(m_SrcImageID, m_DestinationPath, 75); //Variable to monitor functions Success or Failure
if (m_Status != GdPictureStatus.OK)
{
m_Status = GdPictureStatus.OK;
return page_count;
}
page_count++;
}
return page_count;
}
catch (Exception err)
{
//Write err to the event log
}
Is there a way to get more detail of what CreateGdPictureImageFromFile is not liking and why it is getting an UnknownImageFormat? I am using 14.1.0.184 from NuGet.
Thanks for any help.