GetThumbnailImage

G

Guest

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

Private Sub GetThumbnail(ByVal 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.GetThumbnailImage(tWidth, tHeight, AddressOf
TnailAbort, IntPtr.Zero)
tImg.Save(ms, Imaging.ImageFormat.Jpeg)
Dim tNail(CInt(ms.Length - 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.
 
G

Guest

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

Help please!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top