GetThumbnailImage

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

    #1

    GetThumbnailImage

    I am trying to use an Image control to get a thumbnail image with the
    following code:

    Private Sub GetThumbnail(By Val img As Image, ByVal photo As Photo)
    ' Gets a thumbnail image from the file and sets the TnailFile property
    ' in the photo object.

    Dim tImg As Image
    Dim w As Integer = img.Width
    Dim h As Integer = img.Height
    Dim tWidth, tHeight As Integer
    Dim tRatio As Double = h / w ' Get the image aspect ratio

    If tRatio > 0.75 Then
    ' Thumbnail is a portrait
    tHeight = 108
    tWidth = CInt(108 / tRatio)
    Else
    ' Thumbnail is a landscape
    tHeight = CInt(144 * tRatio)
    tWidth = 144
    End If

    Dim ms As New MemoryStream
    Try
    tImg = img.GetThumbnai lImage(tWidth, tHeight, AddressOf
    TnailAbort, IntPtr.Zero)
    tImg.Save(ms, Imaging.ImageFo rmat.Jpeg)
    Dim tNail(CInt(ms.L ength - 1)) As Byte
    tNail = ms.GetBuffer
    photo.TnailFile = tNail
    Finally
    If Not ms Is Nothing Then ms.Close()
    End Try
    End Sub

    When this sub executes I get an "Out of memory" error on an image that is
    1.4MB with no embedded thumbnail. I do not get the error on an image that is
    640KB with an embedded thumbnail, or an image that is 20KB with no embedded
    thumbnail.

    This happens on XP Pro with 512MB ram and Windows 2003 Server with 1GB ram.

    Any help would be greatly appreciated. I have a user down right now because
    of this problem.

    --
    Walt
  • Walt

    #2
    RE: GetThumbnailIma ge

    I should have mentioned, the "Out of memory" error occurs when ececuting the
    img.GetThumbnai lImage(...) method.

    Help please!
    --
    Walt


    "Walt" wrote:
    [color=blue]
    > I am trying to use an Image control to get a thumbnail image with the
    > following code:
    >
    > Private Sub GetThumbnail(By Val img As Image, ByVal photo As Photo)
    > ' Gets a thumbnail image from the file and sets the TnailFile property
    > ' in the photo object.
    >
    > Dim tImg As Image
    > Dim w As Integer = img.Width
    > Dim h As Integer = img.Height
    > Dim tWidth, tHeight As Integer
    > Dim tRatio As Double = h / w ' Get the image aspect ratio
    >
    > If tRatio > 0.75 Then
    > ' Thumbnail is a portrait
    > tHeight = 108
    > tWidth = CInt(108 / tRatio)
    > Else
    > ' Thumbnail is a landscape
    > tHeight = CInt(144 * tRatio)
    > tWidth = 144
    > End If
    >
    > Dim ms As New MemoryStream
    > Try
    > tImg = img.GetThumbnai lImage(tWidth, tHeight, AddressOf
    > TnailAbort, IntPtr.Zero)
    > tImg.Save(ms, Imaging.ImageFo rmat.Jpeg)
    > Dim tNail(CInt(ms.L ength - 1)) As Byte
    > tNail = ms.GetBuffer
    > photo.TnailFile = tNail
    > Finally
    > If Not ms Is Nothing Then ms.Close()
    > End Try
    > End Sub
    >
    > When this sub executes I get an "Out of memory" error on an image that is
    > 1.4MB with no embedded thumbnail. I do not get the error on an image that is
    > 640KB with an embedded thumbnail, or an image that is 20KB with no embedded
    > thumbnail.
    >
    > This happens on XP Pro with 512MB ram and Windows 2003 Server with 1GB ram.
    >
    > Any help would be greatly appreciated. I have a user down right now because
    > of this problem.
    >
    > --
    > Walt[/color]

    Comment

    Working...