Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

24 Experts available now in Live!

Get 1:1 Help Now