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() 3 1006
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(
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()
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( This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. ...
|
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. ...
|
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. ...
|
by: rhungund |
last post by:
Hi all. I'm using a simple thumbnail generating script in VB.NET/GDI.
It uses the GetThumbnailImage method.
It works great when resizing gifs. But when I resize a jpeg the
quality looks...
|
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,...
| |
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...
|
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: 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,...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |