Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Fastest method for converting multipage tiff to array of jpgs?

Posted on 2004-08-13
3
Medium Priority
?
152 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
Suggested Courses

719 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