ImageMan ActiveX
Handling Multi Page Images

The image control currently supports three image formats, DCX , GIF and TIFF, which can contain multiple images per file. Support for multiple image files is provided by the Pages and PageNumber properties.


The Pages property returns the number of pages in the current image file. For all single image files this will be a value of one.


The PageNumber property specifies which image in the file should be displayed. It can be set to a number from zero to the value of the Pages property minus one. When using this property to move through the images in a file it is important to remember to call the Refresh method to display the new page. Also many properties can change based on the attributes of the new image; for instance, the image width or height may have changed. The following example shows the code to add to a command button to display the next image in a file:


If ImageControl1.PageNumber < ImageControl1.Pages - 1 Then

ImageControl1.PageNumber = ImageControl1.PageNumber + 1

' If there's a next page then go to it.


' Update the image stats

lblWidth.Text = str(ImageMan.ImageWidth)

lblHeight.Text = str(ImageControl1.ImageHeight)

End If



A multi-page image is stored all in one file. There are no buffers between images. The first image contains a pointer to the second the second contains a pointer to the next and so on. If you change any of the data in one of the image's pages the whole file would no longer be valid. Functions like Rotate and ReduceTo produce a new image that is most likely a different size then the original.


A common support request is: "I rotate one page of an image in a multi-page file and all the rest of the images disappear."


One of our choices for dealing with this could be to save the whole file every time you made a change to an image. This would be very slow and may not be what you even want. Instead we have opted to let you decide how you would like to deal with multiple page images. The following code uses a hidden control, ImHid, to "store" or access all the pages of the file. The actual page the user looks at is in the visible control, ImVis. The user can rotate or change the file in the visible control all they want to without affecting the number of pages or modifying the original document.



Private Sub GotoPage(nPage As Integer)

If nPage < 0 Or nPage > ImHid.Pages Then

MsgBox "Invalid Page Number."

Exit Sub

End If

ImHid.PageNumber = nPage

ImHid.DstLeft = 0

ImHid.DstTop = 0

ImHid.DstRight = ImHid.ImageWidth

ImHid.DstBottom = ImHid.ImageHeight

ImVis.hImage = ImHid.hImage


End Sub


This code is useful for display purposes but is limited if you want to actually change the original file. If you want to change the original file you could take a couple of approaches.


One approach would be to have similar display code as above. When a user modifies an image the modifications made for a given page could be stored in some kind of structure. When it is time to save the file each unmodified page of the file would be saved from the hidden control. Each page that had been changed would be loaded into another control modified and then saved.



Type ImageInfo

bDirty As Boolean

nRotate As Long ' total degrees rotated Mod(36000)

bInvert As Boolean

bVertMirror As Boolean

bHorzMirror As Boolean

bCropped As Boolean

nSrcLeft As Integer

nSrcTop As Integer

nSrcRight As Integer

nSrcBottom As Integer

End Type

. . .

Dim ImDat() As ImageInfo

. . .

Private Sub SaveImage(sFile As String)

Dim i As Integer

ImHid.Overwrite = No

ImHid.AppendImage = True

ImVis.Overwrite = No

ImVis.AppendImage = True

For i = 0 To ImHid.Pages - 1

If ImDat(i).bDirty <> True Then

ImHid.PageNumber = i

ImHid.SaveAs sFile


GotoPage (i)

ImVis.Rotate = ImDat(i).nRotate

If (ImDat(i).bInvert) Then ImVis.Invert

If (ImDat(i).bVertMirror) Then ImVis.MirrorVertical

If (ImDat(i).bHorzMirror) Then ImVis.MirrorHorizontal

If (ImDat(i).bCropped) Then

ImVis.SrcLeft = ImDat(i).nSrcLeft

ImVis.SrcTop = ImDat(i).nSrcTop

ImVis.SrcRight = ImDat(i).nSrcRight

ImVis.SrcBottom = ImDat(i).nSrcBottom

ImVis.hImage = ImVis.hImage

End If

ImVis.SaveAs sFile

End If

Next i

End Sub


The above code sample leaves the image modification procedures as an exercise for the reader. When the image is loaded the ImDat array is dimensioned and then it is modified with each change of the image. The problem with this code is that in order for this to work the user would have to perform the operations in the same order that you perform them when you save the file at the end. If for example they cropped the image prior to rotating it and you did otherwise you would end up with quite different images. Which leads us to the next approach.


A second approach would be to have a control array, one control for each image. When it came time to save the image each control would save it's associated image. Or a combination of the two approaches would be to add a control to a control array for each page modified. And save either from the original control or the modified control when it comes time to save the whole document.



© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic