Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fastest method for converting multipage tiff to array of jpgs?

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
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…

926 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