473,387 Members | 1,597 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,387 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 2450
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.