Solved

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

Posted on 2007-03-26
2
298 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now