Rotating certain pages on a multitiff and saving gives error

Example requests & Code samples for GdPicture Toolkits.
Post Reply
coloboxp
Posts: 6
Joined: Fri Jul 29, 2016 12:12 pm

Rotating certain pages on a multitiff and saving gives error

Post by coloboxp » Fri Jul 29, 2016 2:52 pm

Hi

I'm having an

Code: Select all

GdPicture.GdPictureStatus.UnsupportedImageFormat
error while trying to save a multitiff after some pages were rotated.

The multi tiff multipage, color, JPEG compressed at 65%, 300dpi

This is my code based on your sample:

Code: Select all

 public void RotateImage(string imagePath, Pages pages, Rotation rotation)
        {
            GdPictureStatus status;
            using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
            {
                bool hasRotation = false;
                
                int imageID = gdpictureImaging.CreateGdPictureImageFromFile(imagePath);

                var compression = gdpictureImaging.GetTiffCompression(imageID);

                status = gdpictureImaging.GetStat();

                if (status == GdPictureStatus.OK)
                {
                    int pageCount = gdpictureImaging.TiffGetPageCount(imageID);

                    for (int i = 1; i <= pageCount; i++)
                    {
                        if (i % 2 != (int)pages)
                        {
                            status = gdpictureImaging.TiffSelectPage(imageID, i);

                            if (status == GdPictureStatus.OK)
                            {
                                status = gdpictureImaging.RotateAngle(imageID, (int)rotation);
                            }

                            if (status != GdPictureStatus.OK)
                            {
                                break;
                            }
                        }
                    }

                   // THIS IS FAILING
                    var tmp = gdpictureImaging.TiffSaveMultiPageToFile(
                        imageID,
                        imagePath + "t",
                        compression,
                        65);

                    gdpictureImaging.ReleaseGdPictureImage(imageID);

                    // overwrite the original with the new copy
                    File.Copy(imagePath + "t", imagePath, true);

                    // delete the copy
                    File.Delete(imagePath + "t");

                  // is it possible to save the current open file directly without creating copies?

                }
            }
        }


    public enum Pages
    {
        Even=0,
        Odd =1
    }

    public enum Rotation
    {
        _90 = 90,
        _180 = 180,
        _270 = 270
    }
Please could you tell me what's wrong?

The project is targeting .NET 3.5

Thank you, best regards.

A.A.

coloboxp
Posts: 6
Joined: Fri Jul 29, 2016 12:12 pm

Re: Rotating certain pages on a multitiff and saving gives e

Post by coloboxp » Fri Jul 29, 2016 4:31 pm

I've fixed it by adding the line specified here.

Code: Select all

        public void RotateImage(string imagePath, Pages pages, Rotation rotation)
        {
            GdPictureStatus status;
            using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
            {
                bool hasRotation = false;
                gdpictureImaging.TiffOpenMultiPageForWrite(true);   
                int imageID = gdpictureImaging.CreateGdPictureImageFromFile(imagePath);

                var compression = gdpictureImaging.GetTiffCompression(imageID);

                status = gdpictureImaging.GetStat();

                if (status == GdPictureStatus.OK)
                {
                    int pageCount = gdpictureImaging.TiffGetPageCount(imageID);

                    for (int i = 1; i <= pageCount; i++)
                    {
                        if (i % 2 != (int)pages)
                        {
                            status = gdpictureImaging.TiffSelectPage(imageID, i);

                            if (status == GdPictureStatus.OK)
                            {
                                status = gdpictureImaging.RotateAngle(imageID, (int)rotation);
                            }

                            if (status != GdPictureStatus.OK)
                            {
                                break;
                            }
                        }
                    }

                    var tmp = gdpictureImaging.TiffSaveMultiPageToFile(
                        imageID,
                        imagePath + "t",
                        TiffCompression.TiffCompressionJPEG,
                        55);

                    gdpictureImaging.ReleaseGdPictureImage(imageID);

                    File.Copy(imagePath + "t", imagePath, true);
                    File.Delete(imagePath + "t");
                }
            }
        }

    public enum Pages
    {
        Even=0,
        Odd =1
    }

    public enum Rotation
    {
        _90 = 90,
        _180 = 180,
        _270 = 270
    }
usage:

Code: Select all

            
           TiffRotator tr = new TiffRotator();
            tr.RotateImage(@"C:\RotationTest\0002.TIF", Pages.Odd, Rotation._180);
Now the problem is that the image is more than two times bigger...

User avatar
Loïc
Site Admin
Posts: 5688
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Rotating certain pages on a multitiff and saving gives e

Post by Loïc » Sat Jul 30, 2016 11:52 am

Hi,

Have you tried with our latest version? We've improved a lot tiff compression.

With best regards,

Loïc

coloboxp
Posts: 6
Joined: Fri Jul 29, 2016 12:12 pm

Re: Rotating certain pages on a multitiff and saving gives e

Post by coloboxp » Wed Sep 14, 2016 5:22 pm

Not yet, we are stucked on v8.5 due to costs :/

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest