473,652 Members | 3,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetThumbnailIma ge 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.Direc tory.GetFiles(s trServerPath,
"*.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.GetThumbn ailImageAbort
dummyCallBack = New
System.Drawing. Image.GetThumbn ailImageAbort(A ddressOf
ThumbnailCallba ck)

' Create the thumbnail
Dim ThumbNailImg As System.Drawing. Image
ThumbNailImg = FullSizeImg.Get ThumbnailImage( 160, 120,
dummyCallBack, IntPtr.Zero)
ThumbNailImg.Sa ve(Response.Out putStream,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
pics.Add(ThumbN ailImg)
Next

DataList1.DataS ource = pics
DataList1.DataB ind()
Nov 18 '05 #1
3 2492
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.M apPath("images\ myfile.jpg")
Dim thumb as image = bmp.GetThumbnai lImage, etc
Response.Conten tType = "image/jpeg
bmp.Save(Respon se.OutputStream , Imaging.ImageFo rmat.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.Direc tory.GetFiles(s trServerPath
"*.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.GetThumbn ailImageAbor
dummyCallBack = Ne
System.Drawing. Image.GetThumbn ailImageAbort(A ddressO
ThumbnailCallba ck

' Create the thumbnai
Dim ThumbNailImg As System.Drawing. Imag
ThumbNailImg = FullSizeImg.Get ThumbnailImage( 160, 120
dummyCallBack, IntPtr.Zero
ThumbNailImg.Sa ve(Response.Out putStream
System.Drawing. Imaging.ImageFo rmat.Jpeg
pics.Add(ThumbN ailImg
Nex

DataList1.DataS ource = pic
DataList1.DataB ind(

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

Bill Borg <an*******@disc ussions.microso ft.com> wrote in message news:<0F******* *************** ************@mi crosoft.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.M apPath("images\ myfile.jpg"))
Dim thumb as image = bmp.GetThumbnai lImage, etc.
Response.Conten tType = "image/jpeg"
bmp.Save(Respon se.OutputStream , Imaging.ImageFo rmat.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.Direc tory.GetFiles(s trServerPath,
"*.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.GetThumbn ailImageAbort
dummyCallBack = New
System.Drawing. Image.GetThumbn ailImageAbort(A ddressOf
ThumbnailCallba ck)

' Create the thumbnail
Dim ThumbNailImg As System.Drawing. Image
ThumbNailImg = FullSizeImg.Get ThumbnailImage( 160, 120,
dummyCallBack, IntPtr.Zero)
ThumbNailImg.Sa ve(Response.Out putStream,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
pics.Add(ThumbN ailImg)
Next

DataList1.DataS ource = pics
DataList1.DataB ind()

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.M apPath("images\ myimage.jpg")
Dim newbmp As Image = bmp.GetThumbnai lImage(20, 20, *Nothing*, IntPtr.Zero

Enjoy

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

Thanks Bill. That was what I needed.

Bill Borg <an*******@disc ussions.microso ft.com> wrote in message news:<0F******* *************** ************@mi crosoft.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.M apPath("images\ myfile.jpg")

Dim thumb as image = bmp.GetThumbnai lImage, etc
Response.Conten tType = "image/jpeg
bmp.Save(Respon se.OutputStream , Imaging.ImageFo rmat.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.Direc tory.GetFiles(s trServerPath

"*.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.GetThumbn ailImageAbor
dummyCallBack = Ne
System.Drawing. Image.GetThumbn ailImageAbort(A ddressO
ThumbnailCallba ck
' Create the thumbnai

Dim ThumbNailImg As System.Drawing. Imag
ThumbNailImg = FullSizeImg.Get ThumbnailImage( 160, 120
dummyCallBack, IntPtr.Zero
ThumbNailImg.Sa ve(Response.Out putStream
System.Drawing. Imaging.ImageFo rmat.Jpeg
pics.Add(ThumbN ailImg
Nex
DataList1.DataS ource = pic

DataList1.DataB ind(


Nov 18 '05 #4

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

Similar topics

5
5623
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 pulling the image from the DB is below if it makes a difference. Thanks in advance private void Page_Load(object sender, System.EventArgs e) {
1
3338
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 will take the embedded thumbnail and actually blow it up to the requested height/width. Does anyone know if Microsoft will be fixing this "feature" or whether there's a work around to force the function to use the full image to scale? Thanks...
5
331
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. 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
8
3192
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, when the original size is big, for example, 800x600 and I generate a small picture (160x120) the quality is terrible for a jpeg and even orse for a gif. How can I get some better images? There is another class? There is some resolution propertie I...
1
9838
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 method requires. I don't understand the callback concept in genreal. What are the callback and callbackData parameters, how are they set up and how are they used? Dim MyImage As Image MyImage = Image.FromFile("C:\Chris6.jpg")
0
1881
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 gdiplus.dll and gdipluswrapper.dll and am able to successfully use many of the GDI+ functions in VB6, but my call to GetthumbnailImage generates a "Bad DLL calling convention" error. Function GetThumbnailImage(thumbWidth As Long, thumbHeight As...
0
1049
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 for CAD (AutoCAD) files. While in explorer, I could see the thumbnail of my CAD files. Can this be accomplished? I already know about the "dwgthumbnail.ocx" thats all over the NET but it doesn't quite work for me. Thanks in advance for your...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.