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.