Solved

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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