The Daily Click ::. Forums ::. Klik Coding Help ::. Q saving image to a file
 

Post Reply  Post Oekaki 
 

Posted By Message

Levirules



Registered
  27/09/2008
Points
  37
20th November, 2009 at 02:22:47 -

Hey all. Two part question. The application I'm developing is a 2D grid based level editor, for reference. The levels save as an array file.

Part 1:
In short, I'd like to know if there is a way to save a frame of an animation from an active object or active picture object to a file. Understanding WHY I want to do this isn't required for the question, but if you're curious, read on.

When you save a map in the level editor, there is a function that uses the Screen Capture object to capture the portion of the screen displaying the map, and saves the image to a file. The game engine is a screen-by-screen game; there is no scrolling, but when you hit an edge of a screen, it loads the next screen. There is a function of the level editor that allows you to input which array to load when you hit one of the 4 sides of the screen. The idea is to display thumbnails of the adjacent screens to give the user a visual instead of just a file name. Currently, I have this working, and it's pretty neat, however, it's not ideal. The thumbnails are generated by loading the full-size screenshots into a frame of an active object, and scaling them to 0.1x. The screenshots are 320x240, which makes the thumnails a cute little 32x24. The Screen Capture Object saves the captures as bmps, which means each image file is around 300kb, as opposed to the 20kb size of a 32x24 bmp. So you can see why I'd like to shrink the image before saving it... If I have a game with 50 screens, that's 15MB just in screenshots for the level editor! Shrinking the images before saving them would mean 50 screens adds up to around 1MB. Drastic difference!

I think I can do this by capturing the screen, saving it to the file, loading the file to an active object, shrinking the active object, screen capturing the active object, and saving the file again with the same name. But... that's annoying, and I'm curious to see if anyone knows a way to save an animation frame to a file.

And I can't remember Part 2 anymore.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
20th November, 2009 at 02:30:19 -

I don't think you can export a frame of an active at runtime (besides perhaps some overlay hackery). But I would recommend that you check out the "Image Manipulator" object which allows you to save images as PNGs/JPEGs. This would mean that you could take your screenshots as normal, convert them to JPEGs and then delete the BMPs. It would still save a lot of space that way.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
20th November, 2009 at 15:08:25 -

I'd just make the thumbnail preview out of tiles as well (each tile being 1/10th scale), and load them in exactly the same way as when you would load the actual level.
It's a bit more work, but I think it should be worth it just so you don't have loads of extra image files.
Plus it will save you that 1Mb.

Capturing an image just sounds like you're being lazy, and trying to take a shortcut.

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  50152

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
20th November, 2009 at 15:16:52 -

Sketchy you don't know how many layers his game has, or how it's being loaded.
What he's doing sounds perfectly fine to me.

 
n/a

Levirules



Registered
  27/09/2008
Points
  37
21st November, 2009 at 15:12:24 -

thanks for the replies. I tried the image manipulator object per your suggestion, and it works pretty well! However, it seems to degrade the image quality a bit more when squashing the image. I think that maybe it doesn't have an algorithm to keep things smooth or take an average of the colors. I'll play with it some more.

As for being lazy, naw dude. Everything is about how much benefit you are getting out of the amount of work. All I need are small little thumbnails that represent maps. Taking screenshots automatically through code and resizing them to create thumbnails isn't really lazy in my book... in fact, I've spent a couple hours on this already, tinkering with this and that. Creating a whole new group of code to load 4 levels into really small boxes would involve a lot more work, and I really don't think it would warrant a better outcome, which means what I'm doing isn't lazy, but makes sense. If you saw the project, you'd see.

Thanks for the replies!

Edit: I also tried another method.. Created a new group which activates upon clicking an active object (and deactivates all other groups). I used two separate cycles. One to save the full size screenshot, another to load it into an active picture object, resize it, and save it. I think the screen capture object has a problem with capturing such a small area. Either way, the resized Active Picture object looks just like the image resized and saved with the image manipulator object, so it looks like that's what I'll be doing! TY!

Edited by Levirules

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st November, 2009 at 17:58:45 -

It's not a "whole new group of code" - it's *exactly* the same code as you're already using to load the actual levels. You could literally just copy & paste the code from one frame to the other, which would have taken less time than the "couple hours" you've already spent - and it would result in a smaller overall game size, and half as many external files.
Obviously it's not worth re-doing it, but maybe you'll get what I'm saying...

 
n/a

Levirules



Registered
  27/09/2008
Points
  37
22nd November, 2009 at 00:08:34 -

edit: I'm working on translating the code to a group to create thumbnails on the fly with the altered level loading code, and it's definitely not a copy & paste operation, but so far it might warrant better results. The second array isn't loading the correct array, rather it's loading the current array, which I'll have to find a fix for. but It is looking a bit cleaner. You win >:0

Though, it certainly isn't going to take less time than it did to figure out how to automate the screen capturing process for the thumbnails, and if it DID take less time to code, that would actually mean that THIS method would be the lazy method. Also, without knowing how my editor is coded, you really don't know how much time or effort it would take to implement this. It's definitely not copying and pasting the load code exactly, there is a lot of modifying that has to be done to it to implement it correctly. So yup.

Edited by Levirules

 
n/a

Rox Flame

Creative Talentician

Registered
  06/10/2004
Points
  383
23rd November, 2009 at 08:07:35 -

I am doing a very similar thing at the moment, with saving out thumbnails etc. I've just gone for the option of using image manipulator to save as jpeg in full size (still way smaller filesize) and then deleting the bmp and using active picture to display them with much nicer looking resize, if i could be bothered I'd recapture that and save it but i kind of like leaving fullsize images there, they could be handy.

 
Current project:
Dynabrick (%70)
   

Post Reply



 



Advertisement

Worth A Click