Public Function main()
'..... REMOVED CODE
Select Case colImgList.Count
Case 0
'Something must be wrong.
bReturn = False
Return False
Case Else
Try
'More then two images so need to call looping CombineImages function to put all in one.
'Tried just saving ImageFormat to .jpeg but didn't work.
Dim imgNew As Image
imgNew = CombineImagesNEW(colImgList, DownloadPath)
bReturn = True
imgNew.Dispose()
imgNew = Nothing
Catch Ex As Exception
bReturn = False
End Try
End Select
'REMOVE ALL TEMP IMAGES TO OLD FOLDER
Dim sMoveName As String
Dim iImageLoop As Integer
For iImageLoop = 1 To colImgList.Count
Dim sCurrentImgName As String
sCurrentImgName = Convert.ToString(colImgList(iImageLoop))
'Make sure file is found before doing a move.
If File.Exists(sCurrentImgName) = True Then
sMoveName = sCurrentImgName.Replace(Name, Name & "\old")
If File.Exists(sMoveName) = False Then
File.Move(sCurrentImgName, sMoveName)
Else
'File already exists so need to change filename so has datetime at beginning
File.Move(sCurrentImgName, sMoveName.Replace("\old\", "\old\" & Now.ToString("yyyyMMdd_hhmmss") & "_"))
End If
End If
Next
Return bReturn
End Function
Public Function CombineImagesNEW(ByVal colImageList As Collection, ByVal sPath As String) As Image
Dim iImgCnt As Integer
Dim iImageLoop As Integer
iImgCnt = colImageList.Count
'get the codec for tiff files
Dim info As ImageCodecInfo = Nothing
Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice 'use the save encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim ep As New EncoderParameters(1)
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))
Dim pages As Bitmap = Nothing
Dim frame As Integer = 0
Dim s As String
frame = 1
'Loop through collection to put all images into one main image.
For iImageLoop = 1 To iImgCnt
If iImageLoop = 1 Then
pages = CType(Image.FromFile(Convert.ToString(colImageList(iImageLoop))), Bitmap)
'save the first frame
pages.Save(sPath, info, ep)
Else
'save the intermediate frames
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
Dim bm As Bitmap = CType(Image.FromFile(Convert.ToString(colImageList(iImageLoop))), Bitmap)
pages.SaveAdd(bm, ep)
bm = Nothing
End If
If frame = iImgCnt Then
'flush and close.
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
pages.SaveAdd(ep)
End If
frame += 1
Next
Return pages
End Function