SHARE
TWEET

[RMXP] Screenshot

ForeverZer0 Jun 17th, 2012 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Screenshot
  3. # Author: ForeverZer0
  4. # Version: 1.0
  5. # Date: 6.17.2012
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. # Script for taking snapshots of the game screen and saving to a PNG file.
  9. #
  10. # Instructions:
  11. #  
  12. #   Use the following script call: Screen.snap(FILENAME, QUALITY)
  13. #     FILENAME - Filename to save as excluding extension. If omitted, one
  14. #                will be generated using configured values
  15. #     QUALITY  - Quality of the image. 0 = High, 1 = Low.
  16. #                 If omiited, high quality will be used by default.
  17. #
  18. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  19.  
  20. module Screen
  21.  
  22.   # Define the directory for snapshots
  23.   DIRECTORY = "Snapshots"
  24.  
  25.   # Define the basename for snapshots
  26.   FILENAME = "snap"
  27.  
  28.   #-----------------------------------------------------------------------------
  29.   # Takes a snapshot of the screen
  30.   #   filename - Filename to save as excluding extension.
  31.   #              A name will be generated if this omitted
  32.   #   quality  - Quality of the screenshot
  33.   #              0 = High quality
  34.   #              1 = Low Quality
  35.   #-----------------------------------------------------------------------------
  36.   def self.snap(filename = nil, quality = 0)
  37.     title = "\0" * 256
  38.     GetPrivateProfileString.call('Game', 'Title', '', title, 256, '.\\Game.ini')
  39.     title.delete!("\0")
  40.     window = FindWindow.call('RGSS Player', title)
  41.     unless File.directory?(DIRECTORY)
  42.       Dir.mkdir(DIRECTORY)
  43.     end
  44.     if filename == nil
  45.       count = 0
  46.       files = Dir.entries(DIRECTORY) - ['.', '..']
  47.       files.collect! {|f| File.basename(f, File.extname(f)) }
  48.       filename = "#{FILENAME}#{count}"
  49.       while files.include?(filename)
  50.         count += 1
  51.         filename = "#{FILENAME}#{count}"
  52.       end
  53.       filename = "#{DIRECTORY}/#{filename}.png"
  54.     end
  55.     ScreenShot.call(0, 0, 640, 480, filename, window, quality)
  56.   end
  57.  
  58.   #-----------------------------------------------------------------------------
  59.   # Private Constants - DO NOT EDIT
  60.   #-----------------------------------------------------------------------------
  61.   GetPrivateProfileString =
  62.     Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
  63.   FindWindow = Win32API.new('user32', 'FindWindow', 'PP', 'I')
  64.   ScreenShot = Win32API.new('screenshot.dll', 'Screenshot', 'LLLLPLL', '')
  65. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top