Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / viewing images in a directory as thumbnails

Author
Message
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 18th Apr 2007 05:43 Edited at: 18th Apr 2007 06:25
ill explain this as best as i can. im currently working on a simple program just for learning experience that takes all image files from a directory then displays them on the screen as icons that can then be used for selecting. kinda like a file browser i guess you could say, but then i want to be able to mouse over the image, select it and then be able to paste it in a grid, like a tile editor. this is for 2D only tho as i am not working in 3D if that makes any difference. im not looking for a full source code or quick way to do it, but rather some ideas on how i can go about doing it, then figure it out myself from that point. im just kinda stumped on where to begin.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Apr 2007 07:40
Your biggest problem is that you haven't got any commands for resizing a full size image to a thumbnail.

What you can do though is load the images in and create sprites from them. You can then scale the sprites and place them in a grid on the screen.

If you create a mouse pointer sprite, hide the normal mouse pointer and position the sprite mouse pointer at MouseX(),MouseY() then you can use sprite collision to detect what image you are over.

If you then check when the mouse button is clicked, the sprite you are currently colliding with is the one to load.

Just shout if you need clarification on anything I just said!

TDK_Man

dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 18th Apr 2007 21:45
thanks for the ideas TDK! you seem to be a perfect person to ask since i can kinda remember your matedit program used the same concept im trying to achieve like where you displayed the textures within a directory as little icons. it's been quite some time since ive looked at matedit but i thought that's how you had it set up. if i have any other questions ill definitely ask and thanks again bud!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Apr 2007 00:25
Yes - that's more or less how it was done in MatEdit, only I didn't use sprite collision - I just calculated the image the mouse was over mathematically based on the image size, grid size, scroll offset and mouse position.

Never thought of the sprite collision idea at the time or I would have used it - it makes things a lot easier...

Just shout if you get stuck with anything...

TDK_Man

dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 19th Apr 2007 05:53 Edited at: 19th Apr 2007 05:55
ok im already stumped lol. ill take this one little step at a time. forgive my stupid questions if i ask something obvious. but right now im trying to figure out a way to get my program to scan the "images/" directory and be able to automatically load up the images without having to actually code the names of the images right into the program itself. for example later if i decide to drop in more tile images into the "images/" directory the program will actually recognize those new images and not have to manually put in the program load image and the new image name. hopefully im making sense on what im trying to accomplish, im just having a hard time determining what commands i can actually use for scanning this directory and then loading all the images in that directory without having a load image command for each individual image.

EDIT - sorry but i dont have any code yet to show since this is what im going to do first in the program. i feel like im asking to have this done for me tho since i dont have any code to show where im stuck.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Apr 2007 10:21
What you are looking for is the Perform Checklist For Files command.

Checklist Quantity() gives you the number of files found in the current working directory, (use CD to change if required).

Checklist Srings$(ItemNum) gives you the filename of each one - similar to how a string array works.

Basically, you can loop through the Checklist Srings$() array to see if the last 4 characters are '.bmp', '.jpg' and so on - storing the path and filename for each one that is a compatible picture format.

TDK_Man

dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 19th Apr 2007 19:27 Edited at: 19th Apr 2007 19:55
ahhh yeah, actually i was kinda looking through the darkbasic commands last night and i had seen those commands. ill give a work with those and see what i can manage to come up with. seems im thinking along the right lines, lets just see if i can actually apply these. thanks for all your time TDK!


EDIT: ok, this definitely is all coming together and makes much better sense now. now im on to something. i have one question real quick though. you said i could loop through the checklist string$ array and check if the last 4 characters are valid image extensions right? now how would i be able to make it distinguish which extensions are image extensions and ignore anything else? or is this an obvious question?

Here's what i have soo far, works nicely for the moment based on the info you provided me.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Apr 2007 21:05 Edited at: 19th Apr 2007 21:07
Along the lines of:



After that, PicFilesOnList is the number of filenames and RealList$() contains all the paths and filenames.

You can have whatever extensions you like on the If ThisExt$= line - so long as your program (DB) can load that filetype.

TDK_Man

dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 20th Apr 2007 05:42 Edited at: 20th Apr 2007 07:00
EDIT - I just worked out some code going off all the info you gave me and the concept works great! Now i have something better to work off of than what i was doing before. this basically takes the concept you gave me of using the checklist to scan the directory of images and display the name of the images in that directory, display how many actual images there are and then paste them as sprites to the screen. this in no way is how im going to do the final program but just to show you im grasping what you taught me. and it works nicely. for every new little tile i added into the directory it would add it to the list and automatically add it to the icons on the screen.

Login to post a reply

Server time is: 2024-09-25 21:30:48
Your offset time is: 2024-09-25 21:30:48