GetThumbnailImage help

G

Guest

I've been able to create a databgrid with files from a folder that I retrieve
using Directory.GetFiles. I've read on the use of GetThumbnailImage but can
not find a good tuturial on its use. I'd like to be able to cycle through the
folder that contains image files and display on the presentation side the
thumbnails directly linking to those files (thus once a user clicks on one it
opens the image).
Asking for too much?
Is there a container that these images could be placed in that I can
populate from my code behind and make "live" (linkable)?
thanx.
 
S

Steve Lutz

Hi Chris:

Here's a page I wrote awhile ago using VB.NET that gets an image from a
remote location, then makes a thumbnail out of it. It'll be easy enough to
grab the image from a local file, and convert this code to C#, once you know
the classes that I've used to accomplish this. I know this is a C#
newsgroup, but all I had is my old VB.NET example handy.

----------

Sub Page_load(Sender As Object, E As EventArgs)

Dim thisURL As String

Dim Req As WebRequest
Dim Resp As WebResponse
Dim myImage As System.Drawing.Image
Dim oThumbNail As System.Drawing.Image
Dim scale As Decimal
Dim newHeight As Integer
Dim newwidth As Integer
Dim oGraphic As Graphics
Dim oRectangle As Rectangle
dim result as Boolean = false

scale = 0.4

' DEFAULT TO SHOW WATERMARK
dim ShowWaterMark as boolean = true

try
if (request.querystring("M") = "N") then
ShowWaterMark = false
end if

catch
ShowWaterMark = true
end try




thisURL = request.querystring("url")

Dim url As New Uri(thisURL)
' Get the eternal image
Req = WebRequest.Create(url)

Try
Resp = Req.GetResponse
Catch exc As Exception
MsgBox(exc.Message)
Exit Sub
End Try

' make sure we got an image back
If Resp.ContentType.IndexOf("image") <> -1 Then

' Load up original Image
' This is where you would load the image from local file instead
myImage = System.Drawing.Image.FromStream(Resp.GetResponseStream)

' setup new size
' if a new height/width is not specified on the querystring, use the
scale.

if len(request.querystring("h") & "") > 0 then
newHeight = request.querystring("h")
newwidth = request.querystring("w")
else
newHeight = scale * myImage.Height
newwidth = scale * myImage.Width
end if
' create a new image
oThumbNail = New Bitmap(newwidth, newHeight, myImage.PixelFormat)
oGraphic = Graphics.FromImage(oThumbNail)
oGraphic.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighSpeed
oGraphic.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed
oGraphic.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
oRectangle = New Rectangle(0, 0, newwidth, newHeight)

oGraphic.DrawImage(myImage, oRectangle)

if (ShowWaterMark) then

' Draw the watermark

' Setup Drawing objects
Dim semiTransBrush As SolidBrush = New
SolidBrush(Color.FromArgb(128, 0, 102, 153))
Dim drawFont As New Font("TarzanaNarrowBold", 18)

' How to draw text
oGraphic.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias

Dim WaterMarkString As String = "Watermark!"
Dim textSize As SizeF = oGraphic.MeasureString(WaterMarkString,
drawFont)
Dim drawPoint As New PointF((newwidth - textSize.Width),
newHeight * 0.6)
oGraphic.DrawString(WaterMarkString, drawFont, semiTransBrush,
drawPoint)


end if

Response.ContentType = "image/Jpeg"

' THIS DUMPS THE BINARY IMAGE OUT THE RESPONSE STREAM
oThumbNail.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)

oThumbNail.Dispose()
result = True
End If

If Not result Then
Response.Redirect("/img/noThumbnail2.gif")
End If
 
G

Guest

Thanx, Actually rhis isn't a C# specific forumn and VB.NET is better for me,
so thanx. Do you have a working URL that I can see the results of this
routine?
I see the reference to "watermark", isn't that usually something on an image
to prevent copying, etc?
Are the thumbnails hyperlinks tot he orignal files?

thanx.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top