473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GetThumbnailImage Question

I am trying to convert the regular sized images in a directory to
thumbnails and then display the thumbnails in a datalist. My code
below is displaying the first image and nothing else after it. What
do I have to do to have the thumbnails displayed in my datalist?
Thanks.

Dim strFile As String
Dim pics As ArrayList = New ArrayList

' Get image folder path on server - use "\" string if root
Dim strServerPath As String = Server.MapPath("photos\")

For Each strFile In System.IO.Directory.GetFiles(strServerPath,
"*.jpg")
' Get the regular sized image
Dim FullSizeImg As System.Drawing.Image
FullSizeImg = System.Drawing.Image.FromFile(strFile)

' Create the delegate
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack = New
System.Drawing.Image.GetThumbnailImageAbort(Addres sOf
ThumbnailCallback)

' Create the thumbnail
Dim ThumbNailImg As System.Drawing.Image
ThumbNailImg = FullSizeImg.GetThumbnailImage(160, 120,
dummyCallBack, IntPtr.Zero)
ThumbNailImg.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
pics.Add(ThumbNailImg)
Next

DataList1.DataSource = pics
DataList1.DataBind()
Nov 18 '05 #1
3 2443
Hi John

First, in the item template of the datalist you need an image control

Second, the image control needs a url (either src= or imageurl=, depending on whether it's a server control)

Third, you can do the url the easy way or the harder-but-cooler way

Easier way: Don't store your thumbnails in the array, instead write them to disk with temp names and store just the names in the array, then bind the source url to those names and you're off

Harder way: Keep your images in the arraylist, but now you need a url that returns each image from memory. Consider GetImage.aspx, which returns a byte stream the browser will interpret as an image, with something like this in PageLoad

Dim bmp As Image = New Bitmap(Server.MapPath("images\myfile.jpg")
Dim thumb as image = bmp.GetThumbnailImage, etc
Response.ContentType = "image/jpeg
bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg

Now you bind the source url to GetImage.aspx and the thumbnail is fed from memory rather than disk

Finally, in my example GetImage returns the *same* image each time, so if your directory has 30 images you'd get the same one each time...not good. A few ways to go about it, buy maybe the easiest is that you build your arraylist with just the file names, pass the file name to GetImage.aspx in a query string, and let GetImage convert it to a thumbnail and stream it back

hth

Bil

P.S. If you're serious about it, there's a great discussion in Dino Esposito's book, Programming Microsoft ASP.NET

----- John wrote: ----

I am trying to convert the regular sized images in a directory t
thumbnails and then display the thumbnails in a datalist. My cod
below is displaying the first image and nothing else after it. Wha
do I have to do to have the thumbnails displayed in my datalist?
Thanks

Dim strFile As Strin
Dim pics As ArrayList = New ArrayLis

' Get image folder path on server - use "\" string if roo
Dim strServerPath As String = Server.MapPath("photos\"

For Each strFile In System.IO.Directory.GetFiles(strServerPath
"*.jpg"
' Get the regular sized imag
Dim FullSizeImg As System.Drawing.Imag
FullSizeImg = System.Drawing.Image.FromFile(strFile

' Create the delegat
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbor
dummyCallBack = Ne
System.Drawing.Image.GetThumbnailImageAbort(Addres sO
ThumbnailCallback

' Create the thumbnai
Dim ThumbNailImg As System.Drawing.Imag
ThumbNailImg = FullSizeImg.GetThumbnailImage(160, 120
dummyCallBack, IntPtr.Zero
ThumbNailImg.Save(Response.OutputStream
System.Drawing.Imaging.ImageFormat.Jpeg
pics.Add(ThumbNailImg
Nex

DataList1.DataSource = pic
DataList1.DataBind(

Nov 18 '05 #2
Thanks Bill. That was what I needed.

Bill Borg <an*******@discussions.microsoft.com> wrote in message news:<0F**********************************@microso ft.com>...
Hi John,

First, in the item template of the datalist you need an image control.

Second, the image control needs a url (either src= or imageurl=, depending on whether it's a server control).

Third, you can do the url the easy way or the harder-but-cooler way.

Easier way: Don't store your thumbnails in the array, instead write them to disk with temp names and store just the names in the array, then bind the source url to those names and you're off.

Harder way: Keep your images in the arraylist, but now you need a url that returns each image from memory. Consider GetImage.aspx, which returns a byte stream the browser will interpret as an image, with something like this in PageLoad:

Dim bmp As Image = New Bitmap(Server.MapPath("images\myfile.jpg"))
Dim thumb as image = bmp.GetThumbnailImage, etc.
Response.ContentType = "image/jpeg"
bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)

Now you bind the source url to GetImage.aspx and the thumbnail is fed from memory rather than disk.

Finally, in my example GetImage returns the *same* image each time, so if your directory has 30 images you'd get the same one each time...not good. A few ways to go about it, buy maybe the easiest is that you build your arraylist with just the file names, pass the file name to GetImage.aspx in a query string, and let GetImage convert it to a thumbnail and stream it back.

hth,

Bill

P.S. If you're serious about it, there's a great discussion in Dino Esposito's book, Programming Microsoft ASP.NET.

----- John wrote: -----

I am trying to convert the regular sized images in a directory to
thumbnails and then display the thumbnails in a datalist. My code
below is displaying the first image and nothing else after it. What
do I have to do to have the thumbnails displayed in my datalist?
Thanks.

Dim strFile As String
Dim pics As ArrayList = New ArrayList

' Get image folder path on server - use "\" string if root
Dim strServerPath As String = Server.MapPath("photos\")

For Each strFile In System.IO.Directory.GetFiles(strServerPath,
"*.jpg")
' Get the regular sized image
Dim FullSizeImg As System.Drawing.Image
FullSizeImg = System.Drawing.Image.FromFile(strFile)

' Create the delegate
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack = New
System.Drawing.Image.GetThumbnailImageAbort(Addres sOf
ThumbnailCallback)

' Create the thumbnail
Dim ThumbNailImg As System.Drawing.Image
ThumbNailImg = FullSizeImg.GetThumbnailImage(160, 120,
dummyCallBack, IntPtr.Zero)
ThumbNailImg.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
pics.Add(ThumbNailImg)
Next

DataList1.DataSource = pics
DataList1.DataBind()

Nov 18 '05 #3
P.S. In Esposito's book, he skips the dummy callback and just does this (which worked for me too)

Dim bmp As Image = New Bitmap(Server.MapPath("images\myimage.jpg")
Dim newbmp As Image = bmp.GetThumbnailImage(20, 20, *Nothing*, IntPtr.Zero

Enjoy

----- John wrote: ----

Thanks Bill. That was what I needed.

Bill Borg <an*******@discussions.microsoft.com> wrote in message news:<0F**********************************@microso ft.com>..
Hi John
First, in the item template of the datalist you need an image control
Second, the image control needs a url (either src= or imageurl=, depending on whether it's a server control)
Third, you can do the url the easy way or the harder-but-cooler way
Easier way: Don't store your thumbnails in the array, instead write them to disk with temp names and store just the names in the array, then bind the source url to those names and you're off
Harder way: Keep your images in the arraylist, but now you need a url that returns each image from memory. Consider GetImage.aspx, which returns a byte stream the browser will interpret as an image, with something like this in PageLoad
Dim bmp As Image = New Bitmap(Server.MapPath("images\myfile.jpg")

Dim thumb as image = bmp.GetThumbnailImage, etc
Response.ContentType = "image/jpeg
bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg
Now you bind the source url to GetImage.aspx and the thumbnail is fed from memory rather than disk
Finally, in my example GetImage returns the *same* image each time, so if your directory has 30 images you'd get the same one each time...not good. A few ways to go about it, buy maybe the easiest is that you build your arraylist with just the file names, pass the file name to GetImage.aspx in a query string, and let GetImage convert it to a thumbnail and stream it back
hth
Bil
P.S. If you're serious about it, there's a great discussion in Dino Esposito's book, Programming Microsoft ASP.NET
----- John wrote: ----
I am trying to convert the regular sized images in a directory t

thumbnails and then display the thumbnails in a datalist. My cod
below is displaying the first image and nothing else after it. Wha
do I have to do to have the thumbnails displayed in my datalist?
Thanks
Dim strFile As Strin

Dim pics As ArrayList = New ArrayLis
' Get image folder path on server - use "\" string if roo

Dim strServerPath As String = Server.MapPath("photos\"
For Each strFile In System.IO.Directory.GetFiles(strServerPath

"*.jpg"
' Get the regular sized imag
Dim FullSizeImg As System.Drawing.Imag
FullSizeImg = System.Drawing.Image.FromFile(strFile
' Create the delegat

Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbor
dummyCallBack = Ne
System.Drawing.Image.GetThumbnailImageAbort(Addres sO
ThumbnailCallback
' Create the thumbnai

Dim ThumbNailImg As System.Drawing.Imag
ThumbNailImg = FullSizeImg.GetThumbnailImage(160, 120
dummyCallBack, IntPtr.Zero
ThumbNailImg.Save(Response.OutputStream
System.Drawing.Imaging.ImageFormat.Jpeg
pics.Add(ThumbNailImg
Nex
DataList1.DataSource = pic

DataList1.DataBind(


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew Banks | last post by:
Is it possible to use GetThumbnailImage with images being pulled from an SQL DB and if so how? All examples I've seen refer to working with an actual image stored on the server. My code for...
1
by: Comcast | last post by:
I understand that one of the limitations of the Image.GetThumbnailImage() function is that it's not really good for creating "large" thumbnails because if it exists in the image file, the function...
5
by: John | last post by:
I am trying to convert the regular sized images in a directory to thumbnails and then display the thumbnails in a datalist. My code below is displaying the first image and nothing else after it. ...
8
by: Fabricio Sperandio | last post by:
Hi everyone, I am trying to generate some thumbnails using System.Drawing.Image Class. Actually the GetThumnailImage method. The question is: How can I get a better thumbnail picture? I mean,...
1
by: GrandpaB | last post by:
I am having difficulty implementing the GetThumbnailImage method. I have read the "Help" files on this method, but remain confused. My problem is understanding the last two parameters that the...
0
by: billsahiker | last post by:
Does anyone know how to call GetthumbnailImage in VB6? I am posting this here because .NET is where most of the use of GDIPlus is found and many of you are/were VB6 folks. I registered the...
0
by: William Cruz | last post by:
The code shown below was copied from a previous post & it works fine for "image files". I would like to make this work like "Windows file Explorer" works when you change the view to "Thumbnail" but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.