Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2006, 01:17 PM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default Multi-Page Tiff storage

Hello, all

I am using GDI to read multi-page tiff images and extract certain pages to create an additional multi-page tiff document.

I am referencing the active frames as a bitmap as follows:

'get image format from original tiff file
Me._img.SelectActiveFrame(FrameDimension.Page, fromPageIndex)
pages = New Bitmap(Me._img)

and saving using the saveadd method.

The problem is, when saving to a new tiff file, the file page size is 4 times that of the original (page size, not file size). I have been searching for days for a way to extract information from the original tiff and carry it over to the new tiff, but to no avail.

I understand that when you load the page index to a bitmap, you are decompressing it (stemming from my experience with JAI).

Is there a way to recompress using the compression of the original tiff?

My full code is as follows:

    '/ <summary>
    '/ Saves the specified subpages to the specified file
    '/ </summary>
    Public Sub savePagesInFile(ByVal filename As String, ByVal fromPageIndex As Integer, ByVal toPageIndex As Integer)
        Dim pages As Bitmap = Nothing
        Dim LastPage As Integer = toPageIndex
        Dim lastPageIndex As Integer = _
         Me._img.GetFrameCount(System.Drawing.Imaging.Frame Dimension.Page) - 1

        If (fromPageIndex >= 0) Then
            ' if there are less pages than the specified toPageIndex
            ' toPageIndex is the last page
            If (toPageIndex > lastPageIndex) Then
                toPageIndex = lastPageIndex
            End If

            'get image format from original tiff file
            Me._img.SelectActiveFrame(FrameDimension.Page, fromPageIndex)
            pages = New Bitmap(Me._img)

            'get Image Codec Info
            Dim codec As ImageCodecInfo = getTiffCodec()

            'get encoder to save
            Dim saveEncoder As System.Drawing.Imaging.Encoder = _
             System.Drawing.Imaging.Encoder.SaveFlag

            'get encoderparam to save multi-frame document
            Dim ep As EncoderParameters = New EncoderParameters(1)
            ep.Param(0) = _
             New EncoderParameter(saveEncoder, CLng(EncoderValue.MultiFrame))

            'save first page with Codec Info
            pages.Save(filename, codec, ep)

            'loop through intended pages
            ep.Param(0) = New EncoderParameter(saveEncoder, CLng(EncoderValue.FrameDimensionPage))
            Dim bmp As Bitmap
            For i As Integer = fromPageIndex + 1 To toPageIndex
                'Append each additional page
                Me.appendPageToFile(filename, i, pages)
            Next

            'create flush encoder param
            ep.Param(0) = New EncoderParameter(saveEncoder, CLng(EncoderValue.Flush))

            'flush image
            pages.SaveAdd(ep)
        End If
    End Sub

    '/ <summary>
    '/ Gets the ImageCodecInfo for tiff images
    '/ </summary>
    Protected Function getTiffCodec() As System.Drawing.Imaging.ImageCodecInfo
        Dim info As ImageCodecInfo = Nothing

        For Each ice As ImageCodecInfo In ImageCodecInfo.GetImageEncoders
            If ice.MimeType.ToLower = "image/tiff" Then
                info = ice
            End If
        Next
        Return info
    End Function

    '/ <summary>
    '/ Appends the specified page to the file
    '/ </summary>
    Public Sub appendPageToFile(ByVal fileName As String, ByVal pageIndex As Integer, ByRef pages As Bitmap)
        Dim ep As EncoderParameters = New EncoderParameters(1)

        'get encoder to save
        Dim saveEncoder As System.Drawing.Imaging.Encoder = _
         System.Drawing.Imaging.Encoder.SaveFlag

        ep.Param(0) = New EncoderParameter(saveEncoder, CLng(EncoderValue.FrameDimensionPage))
        Dim bmp As Bitmap

        'Append each additional page
        Me._img.SelectActiveFrame(FrameDimension.Page, pageIndex)
        bmp = New Bitmap(Me._img)
        pages.SaveAdd(bmp, ep)
    End Sub



Thanks for your help



thanks
__________________
thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
tiff compression sandrina C# 2005 1 December 4th, 2013 02:42 AM
TIFF FILES ricespn Beginning VB 6 1 August 7th, 2013 11:54 PM
intermediate storage sarah lee ASP.NET 1.0 and 1.1 Basics 3 September 11th, 2006 01:31 PM
multi-multi-multiple Insert with subquery??? jmjyiannis SQL Server 2000 1 May 5th, 2006 02:20 PM
how can i view tiff on my web page? cici Classic ASP Professional 1 May 22nd, 2004 12:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.