Saving an image as a *.tiff file

Hello Experts
I have a graphing program that allows the user to export the graph as an image as either a jpeg, tiff, png, gif, or bitmap format. The problem is that one of my clients is having a problem exporting his graph as a tif. When he sent me the file, I had the same problem. The ex.message error message is "A Generic error has occured in GDI+" There was no problem exporting the same file as jpeg or in any of the other image formats. When I loaded one of my graphs, there was no problem exporting as a tiff file.
The error occurs at this line:
image.Save(exportLogFileDialog.FileName, ImageFormat.Tiff);
Any help would be appreciated.
Thanks
pdfalkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pdfalkAuthor Commented:
I think I figured out the problem. The graphs that my program produces are very large, and there must be a size limitation for Tiff files that does not exist for the other image formats. When I reduce the size of my graph I am again able to save the graph as a tiff image. I don't think there is a way around this limitation and I'll just have to tell my client to reduce the size of their graph to create a tiff image,otherwise use a jpeg, giff or png formats.

Michel PlungjanIT ExpertCommented:
There is no size limitation for tiff files
They are sometimes used to hold medical images of gigabytes in size
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

japeteCommented:
Could you provide an image and sample code to check the error?
Thanks.
pdfalkAuthor Commented:
I have attached a jpeg image because expert-exchange will not allow me to upload a tiff file. Anyway, this same image as a tiff file works fine, it is when I try to create a larger tiff file that I get the GDI+ error. I use a switch statement, depending on the file index the user chooses. The image is created in a static class that I have not include because there is a lot of it. Could the error be in my code in creating the image? Why would it only effect tiff files and not jpeg etc...?
switch (exportLogFileDialog.FilterIndex)
                        {
                            case 1:
                                image.Save(exportLogFileDialog.FileName, ImageFormat.Jpeg);
                                break;
                            case 2:
                                image.Save(exportLogFileDialog.FileName, ImageFormat.Tiff);
                                break;
                            case 3:
                                image.Save(exportLogFileDialog.FileName, ImageFormat.Bmp);
                                break;
                            case 4:
                                image.Save(exportLogFileDialog.FileName, ImageFormat.Png);
                                break;
                            case 5:
                                image.Save(exportLogFileDialog.FileName, ImageFormat.Gif);
                                break;
                            default:
                                break;
                        }

Open in new window

example-image.jpg
Michel PlungjanIT ExpertCommented:
could it be a server (folder) limit or full disk?
japeteCommented:
I tried to save your image in TIFF format, and it works well (see code below)
As mplungjan said, check disk space (TIF files are bigger than jpg files), where are you writing target files?
Regards.
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Image img = Bitmap.FromFile(ofd.FileName);
                    SaveFileDialog sfd = new SaveFileDialog();
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        img.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Tiff);
                        MessageBox.Show("OK");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Open in new window

pdfalkAuthor Commented:
I think it is a folder limit. I tried to save a very large jpg and got the same error message. How to I change a folder limit in windows? I am running Vista 64 bit Home Premium.

Thanks
japeteCommented:
In Windows Vista 64 you can apply quotas but I don't think that you can limit the size of individual files.

To check disk quota:
1) Right click on the drive and click on Properties
2) Click on the Quota tab and click on the Show Quota Settings button
Dave BaldwinFixer of ProblemsCommented:
What format are you getting the image in and what x/y size is it?
pdfalkAuthor Commented:
The images grow in the x direction which can be anywhere from 5000 to much higher pixels. There is an example in a previous post.
The y direction is usually about 1100 pixels. The image is created by the program. I am suspecting that there must be a limit to the width of the image in tiff formats though I really have no idea?
Dave BaldwinFixer of ProblemsCommented:
Your example image is 14150 x 900.  It saves as a 36 MB TIF image.  You said the image you're having problems with is bigger.  How big is it?  And what format is it in when you receive it?
pdfalkAuthor Commented:
The files I am saving are not nearly that large - I am not quite sure why your file was so large. My files are in the 2 - 3 MB range. I am able to save TIFF files in the 14000 x 900 range (2.6MB). But once my x value gets much larger is when I get the GDI+ error message. JPEGS I am able to save twice the x value - 30,000pxs. I am not sure what is causing the problem, but I am thinking the best solution is to create two tiff images once I have images that are ~14000+px in the x direction.

Dave BaldwinFixer of ProblemsCommented:
The reason it was so big was because I saved your JPG as an Uncompressed TIF.  Usually programs require 3 x the uncompressed image size to work with them in ram.  So a pic 14000 x 900 size would require about 108 MB of ram to process.  30,000 x 900 would be over 200 MB of ram.
pdfalkAuthor Commented:
I am still not 100% what is going on, but I have written code to create two tiff files when the x dimension is greater that 15,000 pixels. Have not gotten any errors and this solution works for me and my clients
Thanks
Pdfalk
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.