Results 1 to 3 of 3

Thread: [RESOLVED][02/03] Error moving images after using to create new .tiff

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [RESOLVED][02/03] Error moving images after using to create new .tiff

    I have a process that goes out and downloads a list of images:
    imageabc_1.tif
    imageabc_2.tif
    imageabc_3.tif

    As these images are saved I add the name to a collection. Once all images are saved I call a function (imgNew = CombineImagesNEW(colImgList, DownloadPath)) to take all images and combine into one file.

    I then have a process that moves all temp images to a 'old' folder. My first image I have no problem moving but all other images I get the following error:
    System.IO.IOException: The process cannot access the file "c:\.....image_2.tif" because it is being used by another process.

    I was thinking it has something to do with the section of saving the intermediate frames in my CombineImagesNEW function but I can't figure out where I am not closing it.

    Any advice is welcome.

    VB Code:
    1. Public Function main()
    2. '..... REMOVED CODE
    3. Select Case colImgList.Count
    4.                 Case 0
    5.                     'Something must be wrong.
    6.                     bReturn = False
    7.                     Return False
    8.                 Case Else
    9.                     Try
    10.                         'More then two images so need to call looping CombineImages function to put all in one.
    11.                         'Tried just saving ImageFormat to .jpeg but didn't work.
    12.  
    13.                         Dim imgNew As Image
    14.                         imgNew = CombineImagesNEW(colImgList, DownloadPath)
    15.                         bReturn = True
    16.                         imgNew.Dispose()
    17.                         imgNew = Nothing
    18.                     Catch Ex As Exception
    19.                         bReturn = False
    20.                     End Try
    21.             End Select
    22.  
    23.             'REMOVE ALL TEMP IMAGES TO OLD FOLDER
    24.             Dim sMoveName As String
    25.             Dim iImageLoop As Integer
    26.             For iImageLoop = 1 To colImgList.Count
    27.                 Dim sCurrentImgName As String
    28.                 sCurrentImgName = Convert.ToString(colImgList(iImageLoop))
    29.                 'Make sure file is found before doing a move.
    30.                 If File.Exists(sCurrentImgName) = True Then
    31.                     sMoveName = sCurrentImgName.Replace(Name, Name & "\old")
    32.                     If File.Exists(sMoveName) = False Then
    33.                         File.Move(sCurrentImgName, sMoveName)
    34.                     Else
    35.                         'File already exists so need to change filename so has datetime at beginning
    36.                         File.Move(sCurrentImgName, sMoveName.Replace("\old\", "\old\" & Now.ToString("yyyyMMdd_hhmmss") & "_"))
    37.                     End If
    38.                 End If
    39.             Next
    40.  
    41.             Return bReturn
    42.         End Function
    43.  
    44. Public Function CombineImagesNEW(ByVal colImageList As Collection, ByVal sPath As String) As Image
    45.     Dim iImgCnt As Integer
    46.     Dim iImageLoop As Integer
    47.  
    48.     iImgCnt = colImageList.Count
    49.  
    50.     'get the codec for tiff files
    51.     Dim info As ImageCodecInfo = Nothing
    52.     Dim ice As ImageCodecInfo
    53.     For Each ice In ImageCodecInfo.GetImageEncoders()
    54.         If ice.MimeType = "image/tiff" Then
    55.             info = ice
    56.         End If
    57.     Next ice 'use the save encoder
    58.  
    59.     Dim enc As Encoder = Encoder.SaveFlag
    60.     Dim ep As New EncoderParameters(1)
    61.     ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))
    62.     Dim pages As Bitmap = Nothing
    63.     Dim frame As Integer = 0
    64.     Dim s As String
    65.  
    66.     frame = 1
    67.  
    68.     'Loop through collection to put all images into one main image.
    69.     For iImageLoop = 1 To iImgCnt
    70.         If iImageLoop = 1 Then
    71.             pages = CType(Image.FromFile(Convert.ToString(colImageList(iImageLoop))), Bitmap)
    72.             'save the first frame
    73.             pages.Save(sPath, info, ep)
    74.         Else
    75.             'save the intermediate frames
    76.             ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
    77.             Dim bm As Bitmap = CType(Image.FromFile(Convert.ToString(colImageList(iImageLoop))), Bitmap)
    78.             pages.SaveAdd(bm, ep)
    79.             bm = Nothing
    80.         End If
    81.  
    82.         If frame = iImgCnt Then
    83.             'flush and close.
    84.             ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
    85.             pages.SaveAdd(ep)
    86.         End If
    87.         frame += 1
    88.     Next
    89.  
    90.     Return pages
    91.    
    92. End Function
    Last edited by lleemon; Dec 21st, 2006 at 09:52 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width