Solved

Fastest method for converting multipage tiff to array of jpgs?

Posted on 2004-08-13
3
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
shamstar earned 500 total points
ID: 11801599
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picture Branding 5 172
Screen Print 21 239
How do I make Imagemagick work when I have 3 versions of PHP installed? 6 186
Vector Icons 2 132
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

738 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