PDA

View Full Version : Displaying thumbnail images in a .net listview


Codi
01-08-2008, 01:39 PM
Hi,

I'm trying to display a list of thumbnail images using a ListView .net control inside a max rollout.
I've been able to do something close to what I need creating a System.Windows.Forms.ImageList object, filling it with scaled System.Drawing.Bitmap objects and then asigning this ImageList to the ListView.SmallImageList.
The problem is that it doesn't scale properly all the images, some images have diferent aspect ratio and they appear distorted on the list.
After a bit of searching I guessed that the proper way to do it is using the method System.Drawing.Bitmap.GetThumbnailImage (http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Drawing.Bitmap.html) but I have no idea how to use it because it needs a callback and a callbackData parameters wich I dont know how to declare in MaxScript.

Is this a good way to get correctly scaled images into a ImageList? How can I make the GetThumbnailImage call inside MaxScript?

My other question is if there is a way to acces the thumbnail images that are stored in the .max files to get them displayed in the ListView aswel.

Thanks.

RustyKnight
01-08-2008, 08:23 PM
Hi,

I'm trying to display a list of thumbnail images using a ListView .net control inside a max rollout.
I've been able to do something close to what I need creating a System.Windows.Forms.ImageList object, filling it with scaled System.Drawing.Bitmap objects and then asigning this ImageList to the ListView.SmallImageList.
The problem is that it doesn't scale properly all the images, some images have diferent aspect ratio and they appear distorted on the list.
After a bit of searching I guessed that the proper way to do it is using the method System.Drawing.Bitmap.GetThumbnailImage (http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Drawing.Bitmap.html) but I have no idea how to use it because it needs a callback and a callbackData parameters wich I dont know how to declare in MaxScript.

Is this a good way to get correctly scaled images into a ImageList? How can I make the GetThumbnailImage call inside MaxScript?

My other question is if there is a way to acces the thumbnail images that are stored in the .max files to get them displayed in the ListView aswel.

Thanks.Your first approach is good...glad to see you got it working!

I don't know about GetThumbnailImage, I'd be more tempted to write a function to scale the image down to a specified boundry while maintaining the aspect ratio. This would take a little bit of work (and probably slow things slightly), but it would be solution you could implement reasonably quickly and give you time to the look back at other solutions...

But that's just me
Shane

Codi
01-09-2008, 11:54 AM
Ya, I guess that it'll be better if I try another method (DrawImage?) to scale the images.
Thanks for the input :)

Here is a simplified version of the script if anyone is interested:
rollout roll_imatges "Image List" (
button btn_scan "Scan Dir" pos:[10,10]
label lbl_path pos:[100,16]
dotNetControl lv_imatges "System.Windows.Forms.ListView" pos:[10,40] width:360 height:650
fn myCallback = ( return false )
fn carrega_imatges paths_imatges = (
fn callback_abort = ( dotnetObject "System.Drawing.Image+GetThumbnailImageAbort" myCallback())
local ptr_callback_abort = dotNetClass "System.IntPtr"
Llista_Imatges = dotNetObject "System.Windows.Forms.ImageList"
Llista_Imatges.ColorDepth = Llista_Imatges.ColorDepth.Depth24Bit
Llista_Imatges.ImageSize = dotNetObject "System.Drawing.Size" 160 120
for path_imatge in paths_imatges do (
thumb = dotNetObject "System.Drawing.Bitmap" path_imatge
-- Calling GetThumbnailImage this way doesn't work :(
-- thumb = thumb.GetThumbnailImage 160 120 (callback_abort()) (ptr_callback_abort.Zero)
Llista_Imatges.images.add thumb
)
return Llista_Imatges
)
fn inicialitzaListView lv = (
lv.View = (dotNetClass "System.Windows.Forms.View").Details
lv.borderstyle = (dotnetclass "System.Windows.Forms.BorderStyle").fixedsingle
lv.showitemtooltips = true
lv.gridlines = true
lv.checkboxes = false
lv.labeledit = false
lv.Columns.add "Image" 164
lv.Columns.add "Name" 196
)
fn ompleListView lv llista_imatges = (
lv.Clear()
lv.Columns.add "Image" 164
lv.Columns.add "Name" 178
lv.SmallImageList = carrega_imatges llista_imatges
for i = 1 to llista_imatges.count do (
imatge = llista_imatges[i]
ListViewOps.AddLvItem lv pTextItems:#("",(getFilenameFile imatge)) pImgIndex:(i-1)
)
)
on btn_scan pressed do (
dir_imatges = getSavePath caption:"Choose image dir:"
if dir_imatges != undefined do (
lbl_path.text = dir_imatges
fitxers_jpg = getFiles (dir_imatges + "\\*.jpg")
ompleListView lv_imatges fitxers_jpg
)
)
on roll_imatges open do (
inicialitzaListView lv_imatges
)
)
createDialog roll_imatges 380 700

CGTalk Moderation
01-09-2008, 11:54 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.