Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I wanna use GetThumbnailImage Method to show a thumbnail on my page. 1

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Here is what I'm trying so far:
Code:
Public Function ThumbnailCallback() As Boolean
   Return False
End Function 'ThumbnailCallback

Public Sub my_GetThumb(pic As String, e As PaintEventArgs) '
   Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback)
   Dim myOrigBitmap As New Bitmap(pic)
   Dim myNewBitmap As System.Drawing.Image = myOrigBitmap.GetThumbnailImage(40, 40, , IntPtr.Zero)
   Return myNewBitmap
   e.Graphics.DrawImage(myThumbnail, 150, 75)
End Sub 'Example_GetThumb

This is code I got off MSDN, translated to VB. I comment out the e As PaintEventArgs as I am trying to show an image on a page... Am I going in the right direction?

Currently I get the message that my Dim myCallback line is wrong, saying that GetThumbnailImageAbort is a delegate type. I don't know what this error means. Please help?!
 
PS, change the line to this:
Dim myNewBitmap As System.Drawing.Image = myOrigBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero)
 
Here is some code I have used to resize a jpeg or gif image and create a bitmap thumbnail:
Code:
Private Sub makeThumbnail(ByVal filename As String)
        Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(filename)
        Dim thisFormat = g.RawFormat
        Dim thumbSize As New Size()
        Dim root, file As String
        root = myRoot & "images/thumbnails/"
        file = Path.GetFileName(filename)

        thumbSize = newThumbSize(g.Width, g.Height)

        Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)

        If thisFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif) Then
            Response.ContentType = "image/gif"
        Else
            Response.ContentType = "image/jpeg"
        End If


        imgOutput.Save(root & file, thisFormat)

        imgOutput.Dispose()
        g.Dispose()

    End Sub

Private Function newThumbSize(ByVal currentwidth As Integer, ByVal currentheight As Integer)
        ' Calculate the Size of the New image  
        Dim tempMultiplier As Double

        If currentwidth > 100 Then  ' portrait  
            tempMultiplier = 100 / currentwidth
        Else
            tempMultiplier = 1
        End If
        Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
        Return NewSize

    End Function

To use an image from a file, you will have to import system.io

Hope this helps!

drew10
 
Speaking of thumbnails, does anyone know how to make a thumbnail of any file (saved on the SQLServer 2000 database as image type).

The file can be of any type: image, txt, office, xml, html, auto cad, 3d Studio, or some other type not installed on the client computer.

I'd only like to thumbnail the 1st page and, if needed, save the little thumbnail on the database.
NetAngel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top