Autor Tema: Screenshot function  (Leído 1767 veces)

BlackCurtain

  • Full Member
  • ***
  • Mensajes: 187
  • Karma: 9
    • Black Curtain Studio
Screenshot function
« en: Noviembre 24, 2010, 10:19:46 pm »
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 :)
« última modificación: Noviembre 25, 2010, 09:19:43 am por BlackCurtain »

Windgate

  • Hero Member
  • *****
  • Mensajes: 2930
  • Karma: 124
    • TRINIT Asociación de Informáticos de Zaragoza
Re: Screenshot function
« Respuesta #1 en: Noviembre 25, 2010, 10:55:07 am »
You can use:

Código: [Seleccionar]
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

  • Hero Member
  • *****
  • Mensajes: 568
  • Karma: 32
  • I'm the eye in the sky.
    • dyko designs
Re: Screenshot function
« Respuesta #2 en: Noviembre 25, 2010, 01:56:53 pm »
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

  • Full Member
  • ***
  • Mensajes: 187
  • Karma: 9
    • Black Curtain Studio
Re: Screenshot function
« Respuesta #3 en: Noviembre 25, 2010, 09:36:44 pm »
You can use:

Código: [Seleccionar]
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.