How do I create a file preview?

Thumbnail result of a file

Page 1 of 1

9 Replies - 1946 Views - Last Post: 02 August 2010 - 04:54 PM

#1 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

How do I create a file preview?

Posted 14 July 2010 - 07:57 PM

I'm trying to find (through Google or otherwise) some good keywords (or resources) that would explain how to create preview images of a specific file. On Mac OS X, any image format can be viewed in the regular Finder window that the OS knows about. Adding a .psd (Photoshop image) file will at first show an "unrecognized image" preview, until Photoshop itself is installed. Then, each of the .psd files come up as a thumbnail preview for itself once Photoshop is registered.

I've created a map editor for a game, and would like to insert a preview of each full map in its .map file. I'm not sure what I need to look up (keywords, like "file preview", "file thumbnail", etc.).

Finally, (if some of you DO know how this is done), do I create the bitmap preview myself on file save, and then attach that to the front (or back) of the map file's data? Do I leave the format the way it is now (no preview) and have to create (and register with the OS) something that will render the files into preview images whenever the file is accessed inside the Finder (or, in Window's case, Windows Explorer)?

Any direction would be great!

Is This A Good Question/Topic? 0
  • +

Replies To: How do I create a file preview?

#2 tlhIn`toq  Icon User is online

  • Closing in on 5,000
  • member icon

Reputation: 4925
  • View blog
  • Posts: 10,457
  • Joined: 02-June 10

Re: How do I create a file preview?

Posted 14 July 2010 - 08:10 PM

Creating your own file format is no small task. Kudo's for doing it.
How much data is in the actual map portion of the file? A completely backwards way to do it would be to make a JPG, then load all your map information into one of hte EXIF tags. JPG allows for the creation of custom EXIF tags of variable length.

Another plan: Do exactly what MS did for Excel; make it a .zip file with a custom extension. That's right! An Excel 'file' is really a .zip file with a lot of XML documents inside it. Sort of like a Macintosh package. On the mac you see a file, but if you open the package contents you see all the sub files and even executables. You could do that with your map file, making it a .zip with an icon resource, thumbnail jpg and however many other resources you need it to have. The advantage of this is that 3 years from now when you want to add some new feature/resource you just add an additional file to the .zip package but your reading of all the other files go unchanged.

Otherwise, you can do a seek to end of your current file... append a bitmap... then append the size of the bitmap in bytes. This way when you need to read it, you seek to end, get the size, seek backwards that much, read the bitmap.
Was This Post Helpful? 2
  • +
  • -

#3 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

Re: How do I create a file preview?

Posted 15 July 2010 - 05:32 PM

The map currently contains:
  • the path to the tilemap image
  • multiple layers (each an array of shorts which index a tile in the tilemap)
  • general NPC information
    • path to the NPC image map
    • map coordinates
    • direction facing
    • movement patterns such as random or a scripted path

  • obstacle map
  • indices for shadows, special effects, and other "drawn over other layers" attributes


When actually saved, the tilemap image is not saved along with the map. It makes it less portable, but since there are dozens of levels that all rely on the same image, it's more of a waste of space to include all included tiles than simply refer to a single sheet that can be kept in memory. So the bitmap would actually be created and/or updated whenever the file is (re)saved.

Now, if I take your advice and append a bitmap (bit it JPEG or otherwise) to the end of my .MAP file, how exactly do I instruct the computer (Mac, Linux, Windows) to see it in thumbnail view?

I really don't mind being given advice to Google certain keywords (if you know what those keywords are). I'm just at a loss as to WHAT to search for. :P
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Closing in on 5,000
  • member icon

Reputation: 4925
  • View blog
  • Posts: 10,457
  • Joined: 02-June 10

Re: How do I create a file preview?

Posted 16 July 2010 - 05:44 AM

I'm just thinking about this... Paths directly to the map images... Hmmm...
So if you every change your map system, then do they all break?
Wouldn't it be more robust to just store someone's coordinates... then calculate which map they need for that location, at time of need?
Then if you get your maps from some new source 3 years from now, or new map system etc. you reduce the work load converting over.


Quote

Now, if I take your advice and append a bitmap (bit it JPEG or otherwise) to the end of my .MAP file, how exactly do I instruct the computer (Mac, Linux, Windows) to see it in thumbnail view?
If you go that route, you don't. You do it in the other direction: Start with a bitmap that the computer natively knows how to thumbnail, then append to the end of that the rest of your .map data.
Was This Post Helpful? 1
  • +
  • -

#5 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

Re: How do I create a file preview?

Posted 16 July 2010 - 12:07 PM

I'm actually in the process of breaking up the map system myself. The original project contained a ./maps/ folder, which contained all of the .MAP files. All of the game's data (sprite sheets, backgrounds, HUD graphics) were stored in a single data file, which the game engine (and map editor) would simply reference within that structure. So if a new tilemap were to be added, the entire code would have to be reworked to allow it to be included.

I'm trying to decide on a "better" way. I'm thinking XML for most of the data, with the maps containing only the bare details necessary to function, and then relying (more heavily) on LUA scripts to actually add each NPC to the map that needs to be there. The map can contain markers and hotspots by itself (placed in front of doors and other locations that need to be referenced or triggered by the scripts), but the LUA scripts can also dynamically add/remove those as needed.

So I'm trying to figure out a way to give a snapshot of what that map looks like without having to open the map's editor just to do so. Do I paste the bitmap at the beginning or end of my .MAP file (and I don't even care if it's just a glorified .ZIP file, if there will be enough independent data to include), with the size of the bitmap in bytes, and hope that the OS will understand how to display it correctly? Or will it be more complicated, where I need to "help" the OS when it is creating thumbnails as the folder is traversed?
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Closing in on 5,000
  • member icon

Reputation: 4925
  • View blog
  • Posts: 10,457
  • Joined: 02-June 10

Re: How do I create a file preview?

Posted 16 July 2010 - 12:18 PM

Quote

and hope that the OS will

Stop right there. Never trust the OS to do anything you expect/hope/want it to do. Even if it does it this week, it won't after the next automatic update that roles out.
Was This Post Helpful? 1
  • +
  • -

#7 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

Re: How do I create a file preview?

Posted 17 July 2010 - 07:22 PM

So far, keywords such as shell extension look promising. I believe this is what I'm looking for (right?), which -- at least as far as Windows goes -- I simply create a DLL, reference it in specific locations within the registry (CLSID, the .MAP extension, and one of the folder preview or other event notification systems), and make the icon (when accessed via Window's Explorer) show the map preview.

I'll have to do the same thing with Mac and Linux, if there is a way to do this. I just found a few programs such as Xee which will at least view images, although they're not giving me a preview like what I'm hoping for, so I'll keep looking.

More suggestions are welcome, but I'll also try to create a new test format which contains the preview bitmap's size, then its actual bitmap image, and finally, some random garbage data just to check that it works properly. Or is it "random garbage data" followed by the bitmap and size in bytes at the END? Or does it not matter either way if I don't already have shell extensions in place?

Your feedback has been appreciated!
Was This Post Helpful? 0
  • +
  • -

#8 myork  Icon User is offline

  • D.I.C Head

Reputation: 41
  • View blog
  • Posts: 129
  • Joined: 04-March 09

Re: How do I create a file preview?

Posted 26 July 2010 - 08:19 AM

I think this is what you're looking for (at least for windows).

This post has been edited by myork: 26 July 2010 - 08:19 AM

Was This Post Helpful? 1
  • +
  • -

#9 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

Re: How do I create a file preview?

Posted 01 August 2010 - 07:49 AM

That's an excellent link, myork. Very appreciated. I'll search around for Linux and Mac variations, but this looks like exactly what I need for Windows.
Was This Post Helpful? 0
  • +
  • -

#10 NeoTifa  Icon User is offline

  • ¿Dónde están mis pantalones?
  • member icon





Reputation: 1968
  • View blog
  • Posts: 14,472
  • Joined: 24-September 08

Re: How do I create a file preview?

Posted 02 August 2010 - 04:54 PM

Dunno if it would help, but I was browsing the Java API earlier and happened upon javax.imageio and it mentioned thumbnails a few times. http://download.orac...1.4.2/docs/api/
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1