Updating a Multipage Tiff

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
Douglas911
Posts: 1
Joined: Thu Jun 10, 2010 3:08 am

Updating a Multipage Tiff

Post by Douglas911 » Thu Jun 10, 2010 3:20 am

I really struggled with this but I found that the following code worked for me.
Create a windows form that has an Imageviewer1 component and an OpenFileDialog1
I have three buttons. Load, Change, Save.
Some of the code I hand typed, but I believe I have it correct.

Hope this helps

Douglas Shonley
Computer Help
Sturgis, SD

*****************************************************************************************

Code: Select all

Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports Vintasoft.Imaging
Imports Vintasoft.Imaging.Codecs
Imports Vintasoft.Imaging.Codecs.Tiff

Public Class frmTesting
   Dim vTiff As New TiffFile
   Dim vCurrentFileName as String
   Dim vTempFile2 as String = "C:\Temp\Tempfile2.tiff"

 Private Sub butLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLoad.Click
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            vCurrentFileName = OpenFileDialog1.FileName
        Else
            Exit Sub
        End If

        'Load into vTiff
        vTiff = New TiffFile(vCurrentFileName)

        'Move Images into ImageViewer
        For x As Integer = 0 To vTiff.Pages.Count - 1
            ImageViewer1.Images.Add(vTiff.Pages(x).GetImage)
        Next

    End Sub

    Private Sub butChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butChange.Click
        ImageViewer1.Images(1).Rotate(90)

    End Sub

    Private Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click

        'Clear out present vTiff
        vTiff.Pages.Clear()

        butSave.Text = "Updating Tiff"
        butSave.Update()

        'Move images from ImageViewer1 to vTiff
        For x As Integer = 0 To ImageViewer1.Images.Count - 1
            vTiff.Pages.Add(ImageViewer1.Images.Item(x))
        Next

        butSave.Text = "Saving"
        butSave.Update()

        'Save vTiff to a temporary file
        vTiff.Save(vTempFile2)

        butSave.Text = "Disposing"
        butSave.Update()

        'Clean out the tiff
        vTiff.Dispose()

        'Clean out the ImageViewer
        ImageViewer1.Images.ClearAndDisposeItems()

        butSave.Text = "Copying"
        butSave.Update()

        'Copy the tempfile over the top of original file
        My.Computer.FileSystem.CopyFile(vTempFile2, vCurrentFileName, True)

        butSave.Text = "Done"

    End Sub
End Class

Alex
Site Admin
Posts: 1462
Joined: Thu Jul 10, 2008 2:21 pm

Re: Updating a Multipage Tiff

Post by Alex » Thu Jun 10, 2010 2:55 pm

Hello Douglas,

Your code is correct but not optimal!

Version 4.2 of VintaSoftImaging.NET SDK is released today. This version now allows to save processed and/or annotated images back to the source using ImageCollection, please see our ImageViewer and Annotation Demos.

Best regards, Alexander

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest