CreateGdPictureImageFromFile returning 0, ability to get more detail on UnknownImageFormat status

General discussions about GdPicture.NET.
Post Reply
bhemph
Posts: 1
Joined: Fri Sep 23, 2022 2:00 am

CreateGdPictureImageFromFile returning 0, ability to get more detail on UnknownImageFormat status

Post by bhemph » 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:

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
            }
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.

Hugo
Posts: 189
Joined: Tue Dec 18, 2018 10:09 am

Re: CreateGdPictureImageFromFile returning 0, ability to get more detail on UnknownImageFormat status

Post by Hugo » Fri Sep 23, 2022 2:54 pm

Hi there,

Thanks for your question.

From your description the issue comes from this "I have an application that is retrieving an image or pdf from an API."
NOTE: You cannot load PDFs using this method: "CreateGdPictureImageFromFile" (This is exclusively reserved for image formats which PDF is not)
I would advise you to create a process to load these PDFs separately and rasterize them and save them as a GdPicture Image directly from the GdPicturePDF library.

If your issue also occurs on TIFF files then please send me a sample TIFF from your end so I may replicate the issue on my end.
If these are private files, we can further discuss this here: https://orpalis.zendesk.com/hc/en-us/requests/new

Let me know if you need any help doing this.

Regards,
Hugo Cudd
Technical Support

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests