Solved

Fastest method for converting multipage tiff to array of jpgs?

Posted on 2004-08-13
3
151 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

630 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