Screenshot function

Started by BlackCurtain, November 24, 2010, 10:19:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BlackCurtain

The other day I was looking around the wiki for a way to save screenshots and I found the png save function.
While the example shown is a good method, I found it much better doing it like this which eliminates the chance of overwriting old screenshots:
[code language="bennu"]
Global
   int takingscreenshot;
End

//Saving screenshots
process TakeScreenshot()
private
int i=0;
begin
       
           if (takingscreenshot==0)
               takingscreenshot=1;
               graph=screen_get();
            
      for(i=0; i<10000; i+=1)
               if(not file_exists("screen_"+itoa(i)+".png"))
               png_save(0,graph,"screen_"+itoa(i)+".png");  
               break;
               end
               end                                      
                                                             
               map_unload(0,graph);  
           else
               takingscreenshot=0;
           end      
   
   end
[/code]
Which counts from the lowest screenshot number in the file string, avoiding the risk of overwriting any old screenshots. I figured I'd post it here rather than editing the wiki and risking ruining something :P I'm not that familiar with wiki editing.

EDIT: Not sure if itoa(int) is required, I just felt like using it :)

Windgate

You can use:

ftime ( "%d-%m-%y_%Hh%Mm%Ss" , time ( ) )

Instead of itoa(i), this way you can save screenshot in a different run without overwriting existing screens :D

I made a similar process with Bennu3D, and I use F1 key to take screenshots.

It is good to have it in Bennu2D now :D
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

handsource-dyko

Pretty nice bit of code. Did you now that you can also do this with map files?
Maybe handy for creating drawing applications. I once did something similair to
create a demo movie, wich saves every frame in to an fpg file.

BlackCurtain

Quote from: Windgate on November 25, 2010, 10:55:07 AM
You can use:

ftime ( "%d-%m-%y_%Hh%Mm%Ss" , time ( ) )

Instead of itoa(i), this way you can save screenshot in a different run without overwriting existing screens :D

I tried that too, but it just gave me weird random letters and numbers, no date/time stamps.