Home Image-Pro Automation (Macros, Apps, Reports)

SAVING IMAGES IN TIF AND JPG FORMATS . . .

All --

I am having some problems getting IMAGE-PRO 10.0.7 to save images the way that I want.

I am doing a SNAPSHOT of an image which contains some LINE PROFILE INFORMATION in an OVERLAY.  The SNAPSHOT generates an image which is approximately 3000 x 2000.  I am would like to save this image as TIF and as a JPG.

I recorded the CODE below and the files that resulted are exactly what I want.  The TIF IMAGE was approximately 17 MB and the JPG FILE was approximately 1 MB.

I altered the CODE to accept a FILE NAME (with no extension).

When I call the MMBSaveDead CODE, the TIF FILE that is generated by this code is approximately 17 MB.  The JPG FILE that is generated by this code is also approximately 17 MB so I don't think that IMAGE-PRO is responding to the CODE in the same was as it responds to the UI when the CODE was generated.

Q1 -- How does MMBSaveDead need to be altered to resolve this issue so that the JPG FILE is truly a JPG FILE?

Q1 -- Can MMBSaveDead be altered to save the image in a TIF FILE using LZW COMPRESSION?

In the past, I have been directed to use something like the code below to save an image in a TIF FILE,
                                'Save the active image in the appropriate TIF FILE
                                ThisApplication.ActiveImage.File.Format = _
                                    "tif"

                                ThisApplication.ActiveImage.SaveAs _
                                    ( _
                                    TempNewImageFullName _
                                    )
This works but I cannot track down the HELP FILE PAGE that tells me the options for the
ThisApplication.ActiveImage.File.Format
and replacing "tif" with "jpg" results in an IMAGE-PRO CRASH.

Thank you in advance.

-- Matt




    Public Function MMBSaveDead(MyImageFileName As String)

        Dim window1, image1, doc1

        With Application.WindowCommands.Active(Nothing)
            .Run(window1)
        End With

        With Application.WindowCommands.Snap(Nothing)
            .Run(window1, image1)
        End With

        With Application.DocumentCommands.Activate(Nothing)
            .Run(image1, doc1)
        End With

        With Application.DocumentCommands.SaveAs(Nothing)
            .Filename = MyImageFileName & ".tif"
            .Run(image1)
        End With

        With Application.DocumentCommands.Activate(Nothing)
            .Run(doc1, doc1)
        End With

        With Application.DocumentCommands.SaveAs(Nothing)
            .Filename = MyImageFileName & ".jpg"
            .Run(image1)
        End With

        With Application.DocumentCommands.Activate(Nothing)
            .Run(doc1, doc1)
        End With

    End Function




Answers

  • Hi Matt,

    I can reproduce your issue and it looks like once the image was saved to TIF, saving it second time with different extension, saves it also as TIF, but with different extension.
    We will look into the issue, but for now you can use a simple workaround, just save to JPG format first and then to TIF, like this:

        Public Function MMBSaveDead(MyImageFileName As String)
    
            Dim window1, image1, doc1
    
            With Application.WindowCommands.Active(Nothing)
                .Run(window1)
            End With
    
            With Application.WindowCommands.Snap(Nothing)
                .Run(window1, image1)
            End With
    
            With Application.DocumentCommands.Activate(Nothing)
                .Run(image1, doc1)
            End With
    
            With Application.DocumentCommands.SaveAs(Nothing)
                .Filename = MyImageFileName & ".jpg"
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Activate(Nothing)
                .Run(doc1, doc1)
            End With
    
            With Application.DocumentCommands.SaveAs(Nothing)
                .Filename = MyImageFileName & ".tif"
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Activate(Nothing)
                .Run(doc1, doc1)
            End With
    
        End Function
    

    Regards,

    Yuri
  • 2020-09-02-124810

    Yuri --

    Thank you for the diagnosis and the solution.

    Will do.

                                    'Save the active image in the appropriate TIF FILE
                                    ThisApplication.ActiveImage.File.Format = _
                                        "tif"
    
                                    ThisApplication.ActiveImage.SaveAs _
                                        ( _
                                        TempNewImageFullName _
                                        )

    Is there a version of this CODE that would achieve the same results and is there a way to save the IMAGE in a  TIF FILE with LZW COMPRESSION?

    Thanks again.

    -- Matt



  • Hi Matt,

    You can set the Compression property of File to use LZW.
    Here is a sample macro that saves active image to files with LZW and no compression:

        Public Sub SaveWithLZW
            Dim im As McImage=ThisApplication.ActiveImage
            With im.File
                .Format="TIF"
                .Compression=2'TIFFCOMP_LZWDiff
                im.SaveAs("D:\TestLZW.tif")
    
                .Compression=0'no compression
                im.SaveAs("D:\TestNoCompression.tif")
            End With
        End Sub
    

    Yuri
  • 2020-09-03-140547

    Yuri --

    Thank you for the response with

        Sub SaveWithLZW

    This may be helpful for this customer due to the number of image files they are generating.

    Thanks again.

    -- Matt

Sign In or Register to comment.