locked
Converting a multipage tiff to a gif RRS feed

  • Question

  • User-1712672948 posted

    Hi Folks

    As mentioned I am having a problem converting a multipage tif to a mulitpage gif file. I am able to convert the tif file to gif but it loses any multipages. Single file pages are not a problem.

    This is a simple version of the code I am using

            Dim bm As Bitmap = Bitmap.FromFile("C:\S740368.tif")
            bm.Save("C:\S740368.gif", System.Drawing.Imaging.ImageFormat.Gif)

    Is it possible? I am using ASP.NET 2.0 but will be soon moving to 3.5. So is it perhaps possible with 3.5?

    Thanks

    Thursday, October 2, 2008 7:15 AM

All replies

  • User-987726656 posted

    I think you should have a look at the SelectActiveFrame and SaveAdd methods of the Image class in System.Drawing.Image.

    By using SelectActiveFrame in a loop you should be able to step through the pages of the input tiff and use SaveAdd to add them to the new output file.

     /Per

    Monday, October 6, 2008 10:30 AM
  • User-1712672948 posted

     Thanks Persa. I'll try that and let you know how I get on.

     

    Thursday, October 9, 2008 5:39 AM
  • User-1712672948 posted

    Hi Per   

    I've tried as you suggested and got very close to what I want to achieve. But I am still having problems with the SaveAdd fucntion below. I get an error stating:
    'An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
    Additional information: A generic error occurred in GDI+.'

    I am able to loop through the tif image pages and save these as individual gif images by uncommenting the mygif.Save("c:\test_" & i & ".gif") line below. But my problem still remains that I cannot create a mulit-page gif image.

    Am I perhaps using the SaveAdd function incorrectly? Do I need to add a reference?

    Here is my code

    Imports System.Drawing.Imaging
    .
    .
    .
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim enc As Encoder = Encoder.SaveFlag
            Dim encparam As New EncoderParameter(enc, Long.Parse(EncoderValue.MultiFrame))
            Dim encparams As EncoderParameters = New EncoderParameters(1)
            encparams.Param(0) = encparam

            Dim mygif As Image = Image.FromFile("c:\test.tif")
            mygif.Save("c:\test.gif", ImageFormat.Gif)

            For i As Integer = 1 To mygif.GetFrameCount(FrameDimension.Page) - 1

                mygif.SelectActiveFrame(FrameDimension.Page, i)

                'mygif.Save("c:\test_" & i & ".gif")
                mygif.SaveAdd(mygif, encparams)

            Next

        End Sub

     
    Thanks Per

    Ian.

    Monday, December 8, 2008 4:41 AM
  • User-987726656 posted

    I am sorry but a little more investigation gives that the GDI+ GIF encoder used can't create multiframe GIF images...

    So I think you need some graphics toolkit with more advanced GIF functionality. One possibility is GifLib, have a look at http://www.codeplex.com/GifLib.

    /Per

    Monday, December 8, 2008 7:11 AM