Problem Rotating Multipage TIFF

Discussions about image processing and document imaging.
Post Reply
myow
Posts: 10
Joined: Wed Mar 21, 2012 4:34 pm

Problem Rotating Multipage TIFF

Post by myow » Tue Sep 18, 2012 3:57 pm

I am using the following vb code to rotate a multipage tiff image. Before the rotation the value of TiffIsMultiPage is true and multiple pages are displayed when loaded into gdviewer. After this the value of TiffisMultiPage is false and only the first page will display when loaded into the gdviewer. When debugging the value of TiffIsMultiPage changes after the rotate method. I am using GDPicture .Net version 8.5.0.28. Thanks.

Code: Select all

oGdPictureImaging.Rotate(imageID, RotateFlipType.Rotate90FlipNone)
Me.GdViewer1.DisplayFromGdPictureImage(imageID)
Me.GdViewer1.ReloadAnnotations()
Me.GdViewer1.Redraw()

myow
Posts: 10
Joined: Wed Mar 21, 2012 4:34 pm

Re: Problem Rotating Multipage TIFF

Post by myow » Fri Feb 08, 2013 5:36 pm

Been awhile but finally got back to this. In this app, I did not have access to the image file directly since it is provided by a web service. All I had was a byte array of the image. Here is what I used as a workaround. Need to add additional error handling logic. No guaratees but seems to be working so far with the images I have tested with.

Code: Select all

            ' Delete any previous page work files in the log directory.
            Dim workPath As String = "directoryName"
            For Each myFile As String In Directory.GetFiles(workPath, "work*.tif")
                File.Delete(myFile)
            Next

            ' Use the original image data and write out a file named orig.tif in the
            ' directory.
            Dim fs As FileStream = New FileStream(workPath & "orig.tif", FileMode.Create)
            fs.Write(imageData, 0, imageData.Length - 1)
            fs.Flush()
            fs.Close()

            ' Read the orig.tif file and create the individual image files for each page
            ' using the workxxxx.tif file name.  These are placed in the directory.
            oGdPictureImaging.TiffOpenMultiPageForWrite(True)
            Dim workID As Integer = oGdPictureImaging.TiffCreateMultiPageFromFile(workPath & "orig.tif")
            For x As Integer = 1 To oGdPictureImaging.TiffGetPageCount(workID)
                oGdPictureImaging.TiffSelectPage(workID, x)
                oGdPictureImaging.TiffSaveAsMultiPageFile(workID, workPath & "work" & x.ToString.PadLeft(4, "0") & ".tif", TiffCompression.TiffCompressionCCITT4)
            Next
            oGdPictureImaging.ReleaseGdPictureImage(workID)
            oGdPictureImaging.TiffCloseMultiPageFile(workID)

            ' Read the original workxxxx.tif files, rotate them and create a new document with the
            ' name new.tif.
            Dim cnt As Integer = 0
            Dim multiPageID As Integer = oGdPictureImaging.CreateNewGdPictureImage(oGdPictureImaging.GetWidth(workID),
                                                                                   oGdPictureImaging.GetHeight(workID),
                                                                                   oGdPictureImaging.GetBitDepth(workID),
                                                                                   oGdPictureImaging.ARGBI(255, 0, 0, 0))
            Dim inID As Integer
            For Each inFile As String In Directory.GetFiles(workPath, "work*.tif")
                If cnt = 0 Then
                    multiPageID = oGdPictureImaging.CreateGdPictureImageFromFile(inFile)
                    oGdPictureImaging.Rotate(multiPageID, fliptype)
                    oGdPictureImaging.TiffSaveAsMultiPageFile(multiPageID, workPath & "new.tif", TiffCompression.TiffCompressionCCITT4)
                    oGdPictureImaging.ReleaseGdPictureImage(multiPageID)
                Else
                    inID = oGdPictureImaging.CreateGdPictureImageFromFile(inFile)
                    oGdPictureImaging.Rotate(inID, fliptype)
                    oGdPictureImaging.TiffAddToMultiPageFile(multiPageID, inID)
                    oGdPictureImaging.ReleaseGdPictureImage(inID)
                End If
                cnt += 1
            Next
            oGdPictureImaging.ReleaseGdPictureImage(multiPageID)
            oGdPictureImaging.TiffCloseMultiPageFile(multiPageID)

            oGdPictureImaging.ClearGdPicture()

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests