Solved

append pages to an existing multi-page tiff

Posted on 2011-09-28
2
504 Views
Last Modified: 2012-08-13

I am trying to convert a group of jpg files to a single multi-page tiff.

I have gotten as far as saving each file in another format (tiff, obviously), but I have no
clue how to combine them into one multi-page tiff file.

The Google answers I have found all seemed a little incomplete, or not specific to vb.net, so I thought I would try here.

Thanks in advance!

0
Comment
Question by:codefinger
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 36773795
I always like Bob Powell's web site when I am looking for graphics stuff.

Generating Multi-Page TIFF files.
http://www.bobpowell.net/generating_multipage_tiffs.htm
Imports System.IO
Imports System.Drawing.Imaging
 
Public Class Form1
    Inherits System.Windows.Forms.Form
    '/ <summary>
    '/ Required designer variable.
    '/ </summary>
    Private components As System.ComponentModel.Container = Nothing
 
    Private _tiffImage As Image
 
 
    Public Sub New()
        '
        ' Required for Windows Form Designer support
        '
        InitializeComponent()
 
        '
        ' TODO: Add any constructor code after InitializeComponent call
        '
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
    End Sub 'New
 
 
    '/ <summary>
    '/ Clean up any resources being used.
    '/ </summary>
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub 'Dispose
 
#Region "Windows Form Designer generated code"
 
    '/ <summary>
    '/ Required method for Designer support - do not modify
    '/ the contents of this method with the code editor.
    '/ </summary>
    Private Sub InitializeComponent()
        '
        ' Form1
        '
        Me.AllowDrop = True
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(288, 173)
        Me.Name = "Form1"
        Me.Text = "Multi Page Tiff Generator"
    End Sub 'InitializeComponent
 
#End Region
 
 
    '/ <summary>
    '/ The main entry point for the application.
    '/ </summary>
    <STAThread()> _
    Shared Sub Main()
        Application.Run(New Form1)
    End Sub 'Main
 
 
    Protected Overrides Sub OnDragEnter(ByVal e As DragEventArgs)
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim allow As Boolean = True
            Dim s As String
            For Each s In CType(e.Data.GetData(DataFormats.FileDrop), String())
                Dim ext As String = Path.GetExtension(s).ToLower()
                If Not (ext = ".jpg" OrElse ext = ".jpeg" OrElse ext = ".tif" OrElse ext = ".gif" OrElse ext = ".bmp") Then
                    allow = False
                End If
            Next s
            If allow Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.None
            End If
        End If
    End Sub 'OnDragEnter
 
 
    Protected Overrides Sub OnDragDrop(ByVal e As DragEventArgs)
        Dim sa As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
 
        Dim dlg As New SaveFileDialog
        dlg.DefaultExt = ".tif"
        If dlg.ShowDialog() <> DialogResult.OK Then
            Return
        End If
 
        'get the codec for tiff files
        Dim info As ImageCodecInfo = Nothing
        Dim ice As ImageCodecInfo
        For Each ice In ImageCodecInfo.GetImageEncoders()
            If ice.MimeType = "image/tiff" Then
                info = ice
            End If
        Next ice 'use the save encoder
        Dim enc As Encoder = Encoder.SaveFlag
 
        Dim ep As New EncoderParameters(1)
        ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))
 
        Dim pages As Bitmap = Nothing
 
        Dim frame As Integer = 0
        Dim s As String
        For Each s In sa
            If frame = 0 Then
                pages = CType(Image.FromFile(s), Bitmap)
                'save the first frame
                pages.Save(dlg.FileName, info, ep)
            Else
                'save the intermediate frames
                ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
                Dim bm As Bitmap = CType(Image.FromFile(s), Bitmap)
                pages.SaveAdd(bm, ep)
            End If
 
            If frame = sa.Length - 1 Then
                'flush and close.
                ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
                pages.SaveAdd(ep)
            End If
 
            frame += 1
        Next s
    End Sub 'OnDragDrop
 
  
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim sf As StringFormat = CType(StringFormat.GenericTypographic.Clone(), StringFormat)
        sf.Alignment = StringAlignment.Center
        sf.LineAlignment = StringAlignment.Center
        e.Graphics.DrawString("Drop images here to make a multi-page tiff", Font, Brushes.Black, New RectangleF(0, 0, Me.ClientSize.Width, Me.ClientSize.Height), sf)
    End Sub 'Form1_Paint
End Class 'Form1

Open in new window

0
 

Author Closing Comment

by:codefinger
ID: 36817777
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB: Convert 2 dates to specific format 24 52
Problem to file 13 55
Help with preventing downloading a zip file 10 45
VB.net Progress Bar - Maximum Value too large 2 15
I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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