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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Thumbnail images....

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
Hey gang...been on a 6 week sabatical - in Ecuador - where we are building an ASP.NET site on SQL Server 2000 for water quality monitoring -- not much time and access for getting on tek-tips (lucky to get my emails) but back at the University now and high speed net. 8)

When I returned a few days ago I had to build a few pages to open up thumbnail images and thought I'd post the highlights for anyone working in this area. The entire code is linked below; the highlights are as follows:

Without going into great detail lets just say dot NET seems to have images covered pretty well - many options available regarding sizing, formatting, etc... some even say better than several of the image programs out there.

In my case the user selects, say, County, and then populates a listbox with the available sites that have images...then the user clicks on a particular site and the available photo information is returned and the first image in for the site is thumbnailed.

Many in the literature create a particular thumbnail without searching to see whether one is already in place - I chose to do look first, thinking it would be better to see if one is there, if so, use it, otherwise, generate a new thumbnail (there are several "ratio" (height to width) routines out on the net, in my case it was 100px wide for horizonatl, 100 tall for vertical so that part of the code is not used).

Private Sub btnSites_Click(sender As object, e As EventArgs)
'Make sure a site is selected...
If dlSites.SelectedIndex <> -1 Then
...
...connection...
...information returned...
'check to see if a thumbnail exists...
Dim s As String
Dim i As Integer = 0
strPath = &quot;.\AerialPhotos\&quot; & ddCty.SelectedItem.Text & &quot;\Site&quot; & intSite & &quot;\File0001.jpg&quot;
Dim IMAGE_DIRECTORY As String = &quot;.\AerialPhotos\&quot; & ddCty.SelectedItem.Text & &quot;\Site&quot; & intSite & &quot;\&quot;
'get number of images for this site...
For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), &quot;*s.jpg&quot;)
i = i + 1
next
strPaths = &quot;.\AerialPhotos\&quot; & ddCty.SelectedItem.Text & &quot;\Site&quot; & intSite & &quot;\File0001s.jpg&quot;
if i = 0 then 'thumbnail not there...
GenerateThumbnail(strPath, strPaths)
end if
btnPhotos.Visible = True
pnImage.Visible = True
End Sub

'thumbnail routine...
Sub GenerateThumbnail(strPath As String, strPaths As String)
Dim g, g2 As System.Drawing.Image
g = System.Drawing.Image.FromFile(Server.MapPath(strPath))
Dim imgw As Integer = g.Width
Dim imgh As Integer = g.height
If imgw >= imgh Then 'horiz...
imgw = 150
imgh = 99
Else 'vertical...
imgW = 99
imgH = 150
End If
g2 = g.GetThumbnailImage(imgw, imgh, Nothing, IntPtr.Zero)
g2.Save(Server.MapPath(strPaths))
g2.Dispose()
End Sub

...then the user, if they choose this particular site, opens up the entire set of photos...

...the count of photos is obtained as:

Dim s As String
Dim y As Integer
For Each s in Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), &quot;*.jpg&quot;) 'get total count...
y = y + 1
next 'may be a better way but this works...

Next the data for each site is passed to an array to that it can be attached to each image as it comes in...

'open database...
Dim cmdSelect As OLEDbCommand
Dim dbconn As OleDbConnection = New OleDbConnection( _
&quot;Provider=Microsoft.Jet.OLEDB.4.0; &quot; & _
&quot;Data Source=&quot; & Server.MapPath(&quot;.\fpdb\Aerials.mdb;&quot;))
cmdSelect = New OLEDbCommand(&quot;SELECT Site_ID, Photo_Date, Sheet_No, Notes FROM tblPhotos WHERE Site_ID ='&quot; & Request.QueryString(&quot;SiteID&quot;) & &quot;ORDER BY Photo_Date ASC&quot;, dbconn)
dbconn.Open()
Dim WebID(y-1) As String
Dim Photo_Date(y-1) As String
Dim Sheet_no(y-1) As String
Dim Path(y-1) As String
Dim Notes(y-1) As String
i=0
Dim myReader As OleDbDataReader
myReader = cmdSelect.ExecuteReader()
Do While myReader.Read()
WebID(i) = myReader.GetValue(0)
Photo_Date(i) = myReader.GetValue(1)
Sheet_no(i) = myReader.GetValue(2)
Notes(i) = myReader.GetValue(3)
i = i + 1
Loop
myReader.Close()
dbconn.Close()

...and finally the images are brought in to populate the datalist...

imgHeight = currentImage.Height
imgWidth = currentImage.Width
If imgWidth > imgHeight Then
imgWidth = 150
imgHeight = 99
Else
imgWidth = 99
imgHeight = 150
End If
html = &quot;<table border='1' cellpadding='0' cellspacing='1' width='650' height='188'>&quot; & _
&quot;<tr>&quot; & _
&quot;<td width='202' align='center' height='188' rowspan='5'><a href=&quot;&quot;&quot; & strPath & &quot;&quot;&quot; Tooltip='Click to see 300K image'>&quot; & _
&quot;<img src='&quot; & strPaths & &quot;'>&quot; & _
&quot;</a></td>&quot; & _
&quot;<td width='429' height='8' align='left'><b><font color='#000080'> Date photo was taken: </font></b> &quot; & &quot;&quot; & strPhotoDate & &quot;&quot; & &quot;</td>&quot; & _
&quot;</tr>&quot; & _
&quot;<tr>&quot; & _
&quot;<td width='429' height='8' align='left' valign='middle'><b><font color='#000080'> Sheet No location of photo: </font></b> &quot; & &quot;&quot; & strSheetNo & &quot;&quot; & &quot;</td>&quot; & _
&quot;</tr>&quot; & _
&quot;<tr>&quot; & _
&quot;<td width='429' height='8' align='left' valign='middle'><b><font color='#000080'> Open field: </font></b> &quot; & &quot;</td>&quot; & _
&quot;</tr>&quot; & _
&quot;<tr>&quot; & _
&quot;<td width='429' height='50' align='left' valign='top'><b><font color='#000080'> Photo Notes: </font></b> &quot; & &quot;&quot; & strNotes & &quot;&quot; & &quot;</td>&quot; & _
&quot;</td>&quot; & _
&quot;</tr>&quot; & _
&quot;</table>&quot;
pics.Add(html)
Next
dlPictures.DataSource = pics
dlPictures.DataBind()
End If
End Sub

...the pages running these pieces of code (and a link on those pages to the code) can be seen at:


...choose &quot;Cullman&quot; county for the most sites.

Hope it helps. Mr. Frost, glad to see you have taken your rightful postion on this forum -- you have been very helpful over the last year -- good to be back in the USA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top