Solved

How do I save a page out of a TIFF upside down?

Posted on 2007-03-26
2
325 Views
Last Modified: 2013-11-26
Hello,
I have been trying to see why the code below will not save a page out of a TIFF rotated 180 degrees?

I am using VS.NET 2005

Code that I am testing with:

            Dim mImage As Image = Image.FromFile(mPath)
            Dim mPageCount As Integer = mImage.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)

            dstPath = System.Configuration.ConfigurationSettings.AppSettings.Get("DestinationPath")
            dstPath = dstPath & Mid(My.Computer.FileSystem.GetName(mPath), 1, Len(My.Computer.FileSystem.GetName(mPath)) - 4) & "\"
            My.Computer.FileSystem.CreateDirectory(dstPath)
            For i As Integer = 0 To mPageCount - 1
                Dim mOldFileName As String = String.Empty
                Dim mUpsideDown  As String = String.Empty
                mImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, i)
                mOldFileName = dstPath & i & ".tif"
                mUpsideDown = dstPath & i & "_Flipped.tif"
                mImage.Save(mOldFileName)
                mImage.RotateFlip(RotateFlipType.Rotate180FlipXY)
                mImage.Save(mUpsideDown )
            Next



What the code does do is save each page in the same orinentation, so I get a file named:
0.tif
0_fliped.tif

But both files are the same way up.

Am I missing a step?


Thanks in advanced
0
Comment
Question by:ttkachuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 18796803
I had some code that deletes a page from tiff. that uses EncoderParameters.
I think thats the part you are missing for the RotateFlip.
Just change the code to save your new tiff that is rotated.

Imports System.IO
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging

Public Class DeleteAtiff_page
    Dim myImageCodecInfo As ImageCodecInfo
    Dim myEncoder As Encoder
    Dim myEncoderParameter As EncoderParameter
    Dim myEncoderParameters As EncoderParameters
    Function RemoveFirstPage(ByVal file As String) As Stream
        Dim fName As String = file.Substring(file.LastIndexOf("\"))
        Dim tFile As String = "C:\" & fName & ".temp.tif"
        Dim newFileName As String = "C:\" & fName
        Dim Dimension As System.Drawing.Imaging.FrameDimension
        Dim tiffImage As Image = Image.FromFile(file)
        Dimension = New System.Drawing.Imaging.FrameDimension(tiffImage.FrameDimensionsList(0))
        tiffImage.SelectActiveFrame(Dimension, 1)
        tiffImage.Save(tFile)
        Dim pageCount As Integer = tiffImage.GetFrameCount(Dimension)
        Dim newTiff As Image = Image.FromFile(tFile)
        Dim encSave = New Imaging.Encoder(Imaging.Encoder.SaveFlag.Guid)
        Dim encParamsCompress = New Imaging.EncoderParameters(1)
        Dim encParamsMulti = New Imaging.EncoderParameters(2)
        Dim encParamsAddFrame = New Imaging.EncoderParameters(1)
        Dim encParamsCloseFrame = New Imaging.EncoderParameters(1)
        Dim encCompress = New Imaging.Encoder(Imaging.Encoder.Compression.Guid)
        encParamsCloseFrame.Param(0) = New Imaging.EncoderParameter(encSave, Imaging.EncoderValue.Flush)
        encParamsCompress.Param(0) = New Imaging.EncoderParameter(encCompress, Imaging.EncoderValue.CompressionLZW)
        encParamsMulti.Param(0) = New Imaging.EncoderParameter(encCompress, Imaging.EncoderValue.CompressionLZW)
        encParamsMulti.Param(1) = New Imaging.EncoderParameter(encSave, Imaging.EncoderValue.MultiFrame)
        encParamsAddFrame.Param(0) = New Imaging.EncoderParameter(encSave, Imaging.EncoderValue.FrameDimensionPage)
        encParamsCloseFrame.Param(0) = New Imaging.EncoderParameter(encSave, Imaging.EncoderValue.Flush)
        newTiff.Save(newFileName, GetCodecInfo(Imaging.ImageFormat.Tiff), encParamsMulti)
        For i As Integer = 2 To pageCount - 1
            tiffImage.SelectActiveFrame(Dimension, i)
            newTiff.SaveAdd(tiffImage, encParamsAddFrame)
        Next
        newTiff.SaveAdd(encParamsCloseFrame)
        newTiff.Dispose()
        tiffImage.Dispose()
        Kill(tFile)
        IO.File.Copy(newFileName, file, True)
        Kill(newFileName)
        Return New IO.FileStream(file, FileMode.Open)
    End Function
    Private Shared Function GetCodecInfo(ByVal format As Imaging.ImageFormat) As Imaging.ImageCodecInfo
        Dim codecs() As Imaging.ImageCodecInfo
        Dim codec As Imaging.ImageCodecInfo
        Dim clsid As Guid
        Dim i As Integer
        clsid = format.Guid
        codecs = Imaging.ImageCodecInfo.GetImageEncoders()
        For Each codec In codecs
            If clsid.Equals(codec.FormatID) Then Return codec
        Next
    End Function
End Class
0
 

Author Comment

by:ttkachuk
ID: 18807923
Tweaking that up - that seem to work -
Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question