VS 2008 vs/ 2005, Image problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Victory

    VS 2008 vs/ 2005, Image problem?

    Hi,
    I just used VS2008 and migrated a project from 2005 to
    2008. The reason is that MSDN docs is saying the Image
    object in .NET Framework 3.5 has a Finalize method, which i
    want to try out since my app is processing a few image
    files and then saying it is running out of memory. I am
    using the Dispose method of this object to get rid of it
    and then setting it to Nothing. in any case, when i used VS
    2008, intellisense still does not show the Finalize method
    as one of the methods of the object. Any idea why it is
    still using the Image object from .net framework 2.0?
    Please see code below:
    thanks,
    Mars


    Private Function EvaluateTiffIma ge(ByRef displayObject
    As ThreadMessageCl ass, ByVal fileName As String, _

    ByVal startingPageNum As String, ByVal fileExt As String)
    As Boolean

    Dim result As Boolean = False

    ' count of images in the tiff file
    Dim imageIndex As Integer = 0

    Dim propertyValues As Byte() = Nothing
    Dim compressionStri ng As String = ""
    Dim compressionValu e As Int16 = 0
    Dim tiffImage As Image = Nothing

    displayObject.T argetWindow =
    DISPLAY_ID.LIST _PROGRESS

    Dim tiffData As TiffProcessingD ataClass =
    displayObject.M essageData

    Try

    ' using the Imaging Managed objects
    tiffImage = Image.FromFile( fileName)

    If Not (tiffImage Is Nothing) Then

    Dim propertyItems As
    System.Drawing. Imaging.Propert yItem() =
    tiffImage.Prope rtyItems

    For propertyIndex As Integer = 0 To
    propertyItems.L ength

    ' Compression property has an id of 259
    If propertyItems(p ropertyIndex).I d() =
    259 Then

    ' The value of which is mapped to a
    short type (i.e. Int16)
    propertyValues =
    propertyItems(p ropertyIndex).V alue

    ' most significant bit is at higher
    index
    compressionStri ng =
    propertyValues( 1) & propertyValues( 0)
    compressionValu e =
    Convert.ToInt16 (compressionStr ing)

    tiffData.ImageC ompression =
    compressionValu e

    If ((compressionVa lue =
    IMAGE_COMPRESSI ON.COMPRESSION_ CCITTFAX4) And (fileExt =
    ".tif")) Or _
    ((compressionVa lue =
    IMAGE_COMPRESSI ON.COMPRESSION_ HUFFMAN_CCITTRL E) And
    (fileExt = ".jpg")) Then

    result = True
    displayObject.M essageText =
    "...Found " & GetCompressionN ame(compression Value) & "
    Compression for: <" & fileName & ">."

    Else
    displayObject.M essageText =
    "...Error: " & GetCompressionN ame(compression Value) & "
    Compression: <" & fileName & ">."
    displayObject.I sError = True
    End If
    DisplayMessage( displayObject)

    ' found what we are looking for
    Exit For
    End If
    Next

    Application.DoE vents()

    ' release the reference to the image object
    imageIndex += 1

    Else

    displayObject.M essageText = "...Error: GDI+
    error was unable to create a document for <" & fileName &
    ">."
    displayObject.I sError = True
    DisplayMessage( displayObject)

    End If
    Catch ex As Exception

    Dim innerExceptionS tring As String = Nothing

    If ex.InnerExcepti on Is Nothing Then
    innerExceptionS tring = "No inner exception"
    Else
    innerExceptionS tring =
    ex.InnerExcepti on.InnerExcepti on.Message
    End If

    displayObject.M essageText = "An exception
    occurred: <" & ex.Message & ">, this error happened when "
    & _

    "Procedo was trying to process file: <" & fileName & ">
    inner exception: <" & _

    innerExceptionS tring & ">."
    displayObject.I sError = True
    displayObject.T argetWindow =
    DISPLAY_ID.LIST _RESULT
    DisplayMessage( displayObject)

    Finally

    If tiffImage IsNot Nothing Then
    ' tiffImage.Final ize() this line has a
    syntax error when it is uncommented
    tiffImage.Dispo se()
    tiffImage = Nothing
    End If

    End Try

    Return result
    End Function

    *** Sent via Developersdex http://www.developersdex.com ***
  • Stanimir Stoyanov

    #2
    Re: VS 2008 vs/ 2005, Image problem?

    Hi Mars,

    You do not see and cannot use the Finalize method of the Image class because
    it is protected and only accessible for use within the Image and/or any
    derivative classes. A good practive would be to use the 'using' clause on an
    Image instance so that you do not have to call Dispose manually and write
    code such as tiffImage = Nothing:

    Using img as Image = Image.FromFile( "...")
    ' Make use of img here...
    End Using

    img would then be automatically disposed of.

    This page on MSDN might give you more insight on how the Finalize method
    works and should be used.
    --
    Stanimir Stoyanov


    "Victory" <csharp@devdex. comwrote in message
    news:O%23FZpP6O JHA.3936@TK2MSF TNGP06.phx.gbl. ..
    Hi,
    I just used VS2008 and migrated a project from 2005 to
    2008. The reason is that MSDN docs is saying the Image
    object in .NET Framework 3.5 has a Finalize method, which i
    want to try out since my app is processing a few image
    files and then saying it is running out of memory. I am
    using the Dispose method of this object to get rid of it
    and then setting it to Nothing. in any case, when i used VS
    2008, intellisense still does not show the Finalize method
    as one of the methods of the object. Any idea why it is
    still using the Image object from .net framework 2.0?
    Please see code below:
    thanks,
    Mars
    >
    >
    Private Function EvaluateTiffIma ge(ByRef displayObject
    As ThreadMessageCl ass, ByVal fileName As String, _
    >
    ByVal startingPageNum As String, ByVal fileExt As String)
    As Boolean
    >
    Dim result As Boolean = False
    >
    ' count of images in the tiff file
    Dim imageIndex As Integer = 0
    >
    Dim propertyValues As Byte() = Nothing
    Dim compressionStri ng As String = ""
    Dim compressionValu e As Int16 = 0
    Dim tiffImage As Image = Nothing
    >
    displayObject.T argetWindow =
    DISPLAY_ID.LIST _PROGRESS
    >
    Dim tiffData As TiffProcessingD ataClass =
    displayObject.M essageData
    >
    Try
    >
    ' using the Imaging Managed objects
    tiffImage = Image.FromFile( fileName)
    >
    If Not (tiffImage Is Nothing) Then
    >
    Dim propertyItems As
    System.Drawing. Imaging.Propert yItem() =
    tiffImage.Prope rtyItems
    >
    For propertyIndex As Integer = 0 To
    propertyItems.L ength
    >
    ' Compression property has an id of 259
    If propertyItems(p ropertyIndex).I d() =
    259 Then
    >
    ' The value of which is mapped to a
    short type (i.e. Int16)
    propertyValues =
    propertyItems(p ropertyIndex).V alue
    >
    ' most significant bit is at higher
    index
    compressionStri ng =
    propertyValues( 1) & propertyValues( 0)
    compressionValu e =
    Convert.ToInt16 (compressionStr ing)
    >
    tiffData.ImageC ompression =
    compressionValu e
    >
    If ((compressionVa lue =
    IMAGE_COMPRESSI ON.COMPRESSION_ CCITTFAX4) And (fileExt =
    ".tif")) Or _
    ((compressionVa lue =
    IMAGE_COMPRESSI ON.COMPRESSION_ HUFFMAN_CCITTRL E) And
    (fileExt = ".jpg")) Then
    >
    result = True
    displayObject.M essageText =
    "...Found " & GetCompressionN ame(compression Value) & "
    Compression for: <" & fileName & ">."
    >
    Else
    displayObject.M essageText =
    "...Error: " & GetCompressionN ame(compression Value) & "
    Compression: <" & fileName & ">."
    displayObject.I sError = True
    End If
    DisplayMessage( displayObject)
    >
    ' found what we are looking for
    Exit For
    End If
    Next
    >
    Application.DoE vents()
    >
    ' release the reference to the image object
    imageIndex += 1
    >
    Else
    >
    displayObject.M essageText = "...Error: GDI+
    error was unable to create a document for <" & fileName &
    ">."
    displayObject.I sError = True
    DisplayMessage( displayObject)
    >
    End If
    Catch ex As Exception
    >
    Dim innerExceptionS tring As String = Nothing
    >
    If ex.InnerExcepti on Is Nothing Then
    innerExceptionS tring = "No inner exception"
    Else
    innerExceptionS tring =
    ex.InnerExcepti on.InnerExcepti on.Message
    End If
    >
    displayObject.M essageText = "An exception
    occurred: <" & ex.Message & ">, this error happened when "
    & _
    >
    "Procedo was trying to process file: <" & fileName & ">
    inner exception: <" & _
    >
    innerExceptionS tring & ">."
    displayObject.I sError = True
    displayObject.T argetWindow =
    DISPLAY_ID.LIST _RESULT
    DisplayMessage( displayObject)
    >
    Finally
    >
    If tiffImage IsNot Nothing Then
    ' tiffImage.Final ize() this line has a
    syntax error when it is uncommented
    tiffImage.Dispo se()
    tiffImage = Nothing
    End If
    >
    End Try
    >
    Return result
    End Function
    >
    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Victory

      #3
      Re: VS 2008 vs/ 2005, Image problem?

      Ok, i changed the logic to use the Using statement. And i
      made sure i have Microsoft .NET Framework 3.5 SP1
      installed. But when i use the references and i check the
      System.Drawing, i see that its version is 2.0.0.0 and its
      Runtime version in the Add Reference dialog says
      v2.0.50727. Is this the correct .net framework 3.5 sp1
      version?

      Mars

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Tom Shelton

        #4
        Re: VS 2008 vs/ 2005, Image problem?

        On 2008-11-03, Victory <csharp@devdex. comwrote:
        Ok, i changed the logic to use the Using statement. And i
        made sure i have Microsoft .NET Framework 3.5 SP1
        installed. But when i use the references and i check the
        System.Drawing, i see that its version is 2.0.0.0 and its
        Runtime version in the Add Reference dialog says
        v2.0.50727. Is this the correct .net framework 3.5 sp1
        version?
        >
        Mars
        >
        *** Sent via Developersdex http://www.developersdex.com ***
        Yes. .NET 3.0 and 3.5 still use the 2.0 runtime. 3.0 and 3.5 are just
        extensions to the existing 2.0 framework.

        --
        Tom Shelton

        Comment

        Working...