Solved

Fastest method for converting multipage tiff to array of jpgs?

Posted on 2004-08-13
3
143 Views
Last Modified: 2013-11-19
The following is code from a web service that returns an array of jpg pages
(as byte arrays) from the requested multi-page tiff image to the calling
client.

My manager has accepted it, but has asked me to nose around the net for
ways to improve performance (without using any third party tools.)

The code works and the quality is acceptable, but is a faster solution possible?

        Dim cms as new CCMSMessage()
        Dim framecount As Integer
        Dim oimg As System.Drawing.Image
        Dim imgbytes As Byte()
        Dim iPageNum As Integer
        Dim iTotalPages As Integer

        Dim encodecinfo As System.Drawing.Imaging.ImageCodecInfo

        Dim encparams As System.Drawing.Imaging.EncoderParameters

        Dim eps As EncoderParameters = New EncoderParameters(1)

        Dim j As Integer
        Dim encoders As ImageCodecInfo()
        Dim mimeType As String
        Dim ici As ImageCodecInfo
        Dim intquality As Integer
        intquality = 10

        eps.Param(0) = New
EncoderParameter(System.Drawing.Imaging.Encoder.Quality, intquality)

        mimeType = "image/jpeg"

        encoders = ImageCodecInfo.GetImageEncoders
        For j = 0 To encoders.Length
            If encoders(j).MimeType = mimeType Then
                ici = encoders(j)
                Exit For
            End If
        Next

        Try
            m_tiff = System.Drawing.Image.FromFile(ls_filename)
            m_fd = New
System.Drawing.Imaging.FrameDimension(m_tiff.FrameDimensionsList(0))
            iTotalPages = m_tiff.GetFrameCount(m_fd)
            Dim pages(iTotalPages - 1) As tiffclass
            Dim tiffpage(iTotalPages - 1) As MemoryStream
            For iPageNum = 1 To iTotalPages
                m_fd = New
System.Drawing.Imaging.FrameDimension(m_tiff.FrameDimensionsList(0))
                m_tiff.SelectActiveFrame(m_fd, iPageNum - 1)
                tiffpage(iPageNum - 1) = New MemoryStream()
                m_tiff.Save(tiffpage(iPageNum - 1), ici, eps)
                oimg = oimg.FromStream(tiffpage(iPageNum - 1))
                imgbytes = tiffpage(iPageNum - 1).GetBuffer()
                Dim singlepage As New tiffclass()
                singlepage.tiffpage = imgbytes
                ReDim Preserve cms.Tiff2JpgPageArray(iPageNum - 1)
                cms.Tiff2JpgPageArray(iPageNum - 1) = singlepage
            Next

            oimg.Dispose()

            cms.FunctionSuccess = True

        Catch ex As Exception
            cms.ErrDescription = ex.Message
        End Try

        Return cms



Thanks in advance.

0
Comment
Question by:codefinger
3 Comments
 
LVL 8

Accepted Solution

by:
shamstar earned 500 total points
Comment Utility
There is very little speed improvement you could get here, that is mainly because most of what you are doing here is unavoidable and seems to be unoptimizable.  You would get the best performance increase if you were able to modify the file reading and saving (encoding and decoding) because your code is geared to use that functionality, but these are very much likely to be highly optimised already.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now