[bb] Smart ScreenShot Taker by Kozmi [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Smart ScreenShot Taker
Author : Kozmi
Posted : 1+ years ago

Description : The function will take a screenshot and remember the last
screenshot taken through that of a data file which the
function creates to obtain the last screenshot taken!
You can also specify a directory where you want the screenshots to be put at as well. This function is very useful for any application where you might need to take screenshots on a regular basis and don't wont to lose existing screenshots! I hope you find this code useful like i have.


Code :
Code (blitzbasic) Select
Global Int1% ;For writing to our '.egl' datafile

;hit spacebar to save a screenshot
If KeyHit(57) = True Then Screenshot()


Function Screenshot()

ChangeDir "E:Blitz3DBlitz3D Demosfpstestegyptian levelScreenShots"

screenin = ReadFile("screenshot.egl") ; you can change the extension to whatever you want!
If screenin = 0 Then currentshot = 0:Goto phase2
currentshot = ReadInt( screenin )
 CloseFile( screenin )

.phase2 iFileNumber% = currentshot
   Repeat
       iFileNumber = iFileNumber + 1
       sFileName$ = "Egyptian_Level" + String$("0", 3 - Len(Str$(iFileNumber))) + iFileNumber + ".bmp"
   Until Not(FileType(sFileName))

Int1 = iFileNumber

screenout = WriteFile("screenshot.egl") ; Same as above!
WriteInt( screenout, Int1 )
   CloseFile( screenout )
   
    SaveBuffer FrontBuffer(), sFileName

ChangeDir "E:Blitz3DBlitz3D Demosfpstestegyptian level" ; Change back to previous directory

End Function


Comments :


Rob Farley(Posted 1+ years ago)

 Would it not be easier...
SaveBuffer FrontBuffer(), "Screenshot " + currentdate() + " " + currenttime() + ".bmp"This will also date/time stamp your screenies.This is only a problem if you're going to take a screenshot faster than every second or for over a 100 year period, even then you could stick a millisecs() on the end to fix that problem.


Kozmi(Posted 1+ years ago)

 Well... Your example code is fine for what it does in all..But what if you don't want your screenshots cluttering up along with your other media files? This is where this is nice, Because this function will allow you to store thescreenshots into another directory plus also remember the last screenshot taken so that it wont over write an existingscreenshot(s) that you may want to keep for some reason or another?! I realize your code could also be changed to store into a different directory as well... But this code I posted does serve it's purpose too! People can use this as they wish to... Or they can use your's... It doesn't matter though, Because I created this yesterday for a test-demo I was working with, And I thought I would post it to share with others on here... They are free to use this if they want! :)


Rob Farley(Posted 1+ years ago)

 Glenn,The code modification to put screenies into another dir would beSaveBuffer FrontBuffer(), "[YOUR DIR]/Screenshot " + currentdate() + " " + currenttime() + ".bmp"Which is a fairly basic change.Furthermore this would create unique filenames as long as you don't take screenshots for over 100 years or quicker than every second as I mentioned above. You can easily tell what the last file is as it is the one with the most recent time, or indeed click on the last modified heading in windows explorer to sort them.I'm not attacking your work just presenting what I believe to be a more elegant solution.


Kozmi(Posted 1+ years ago)

 Ok Rob,Your code is more simple & straight forward and all...But what if I don't want a time/data stamp? But I merly just want to include a name plus a number instead then?Im' sure you could write another example showing a more simplier way to do this as well... But the fact here is,even known my code has a little bit more to it as far asprogramming steps are concerned and all... It still serve's its purpose!!! Plus this code isn't that bad either! It may not be a simple one-liner like yours!! But it does have a nice setup as well! Plus if someone wanted to learn how to create a data file to read & write information too... At least this shows a starting point! Like I said above as well. This code work's fine for me, and I merly wanted to share it with other Blitz users on here! If they feel it isn't worth the bother and all... They don't have to download it, Or copy & paste it! they are free to use this code here... or your's if they perfer!The point here is... they both do the same thing! And that's all that matters here!


tesuji(Posted 1+ years ago)

 HiCurrenttime() outputs colons which are not valid windows filesystem characters. SaveBuffer FrontBuffer(), "dir/filename-"+MilliSecs() + ".bmp"Works for me ;-pBoth techniques have their merits I'm sure.Cheers,S.


Rob Farley(Posted 1+ years ago)

 filename$ = "dir/screenshot "+CurrentDate() + " " + Left(CurrentTime(),2)+Mid(CurrentTime(),4,2)+Right(CurrentTime(),2)+".bmp"