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

General discussions about GdPicture.NET.
Post Reply
bhemph
Posts: 2
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: 194
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

bhemph
Posts: 2
Joined: Fri Sep 23, 2022 2:00 am

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

Post by bhemph » Wed Nov 09, 2022 10:59 pm

Hugo,

Yes, as I said the PDF files go to a different function. This function only receives the TIFF files. Also sending you the files will do no good in replicating anything because as I said, the file conversion is successful when I get the files and run them through the code manually. I updated to 14.1.0.188 from NuGet which helped to reduce the frequency of the 0 returned from CreateGdPictureImageFromFile and GetStat() outputting UnknownImageFormat. It still is happening from time to time though. Are there file system handles or locks by the OS that would be giving this same type of response? Or any other type of reason that a person would expect a different type of error code to explain what is happening, but are instead given this generic invalid file type of response instead? Since the files process just fine after the fact, it isn't the files themselves but seems like it must be something with the process and more that way which was why I asked about a way to get better details or debug info as to what is going on. Whatever is happening has to be captured in the instant the message is given since the situation to cause the error cannot be replicated after the fact.

Thanks,
Brent

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests