The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on April 05, 2010, 11:08:51 PM

Title: Screenshot
Post by: modern algebra on April 05, 2010, 11:08:51 PM
Screenshot
Version: 1.0
Author: 66rpg.com & modern algebra
Date: April 5, 2010

Version History



Description


This script allows the player to take a screenshot of any area in the game that he/she wants. Useful for sharing achievements I suppose. I made it for my own nefarious purposes and without thinking whether it would have any real purpose in an actual RM game.

Features


Instructions

Please see the header. It's very simple.

Script


Code: [Select]
#==============================================================================
#  Screenshot
#  Version: 1.0
#  Author: modern algebra (rmrk.net)
#  Date: April 5, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#    This script allows the player to take a screenshot of any area in the game
#   that he/she wants. Useful for sharing achievements I suppose.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#    All you need to do is set which button you want to use for taking
#   screenshots with at line 31, and set the destination folder for screenshots
#   at line 33.
#    If you want to force a screenshot, you can put this code in a call script:
#       $scene.take_screenshot
#==============================================================================
#==============================================================================
# ** Scene_Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new constant - MA_SCREENSHOT_BUTTON, MA_SCREENSHOT_PATH
#    aliased method - update
#==============================================================================

class Scene_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * CONSTANTS
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  #  MA_SCREENSHOT_BUTTON - the button to press to take a Screenshot
  MA_SCREENSHOT_BUTTON = Input::F5
  #  MA_SCREENSHOT_PATH - the path to save the file
  MA_SCREENSHOT_PATH = "Screenshot "
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modag_screenshot_upd_9ik2 update
  def update (*args)
    modag_screenshot_upd_9ik2 (*args) # Run Original Method
    if Input.trigger? (MA_SCREENSHOT_BUTTON)
      take_screenshot
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Take Screenshot
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def take_screenshot
    x = 1
    while FileTest.exist? ("#{MA_SCREENSHOT_PATH}#{x}.png")
      x += 1
    end
    Graphics.snap_to_bitmap.make_png (x.to_s, MA_SCREENSHOT_PATH, 1)
  end
end
#==============================================================================
#  Everything below this point is the PNG Saver script, written by 66rpg.com
#==============================================================================

# PNG Saver by 66rpg.com

module Zlib
  class Png_File < GzipWriter
    def make_png(bitmap, mode = 0)
      @bitmap, @mode = bitmap, mode
      self.write(make_header)
      self.write(make_ihdr)
      self.write(make_idat)
      self.write(make_iend)
    end
    def make_header
      return [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].pack('C*')
    end
    def make_ihdr
      ih_size               = [13].pack('N')
      ih_sign               = 'IHDR'
      ih_width              = [@bitmap.width].pack('N')
      ih_height             = [@bitmap.height].pack('N')
      ih_bit_depth          = [8].pack('C')
      ih_color_type         = [6].pack('C')
      ih_compression_method = [0].pack('C')
      ih_filter_method      = [0].pack('C')
      ih_interlace_method   = [0].pack('C')
      string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
               ih_compression_method + ih_filter_method + ih_interlace_method
      ih_crc = [Zlib.crc32(string)].pack('N')
      return ih_size + string + ih_crc
    end
    def make_idat
      header  = "\x49\x44\x41\x54"
      data    = @mode == 0 ? make_bitmap_data0 : make_bitmap_data1
      data    = Zlib::Deflate.deflate(data, 8)
      crc     = [Zlib.crc32(header + data)].pack('N')
      size    = [data.length].pack('N')
      return size + header + data + crc
    end
    def make_bitmap_data0
      gz = Zlib::GzipWriter.open('png2.tmp')
      t_Fx = 0
      w = @bitmap.width
      h = @bitmap.height
      data = []
      for y in 0...h
        data.push(0)
        for x in 0...w
          t_Fx += 1
          if t_Fx % 10000 == 0
            Graphics.update
            if t_Fx % 100000 == 0
              s = data.pack('C*')
              gz.write(s)
              data.clear
            end
          end
          color = @bitmap.get_pixel(x, y)
          data.push(color.red, color.green, color.blue, color.alpha)
        end
      end
      s = data.pack('C*')
      gz.write(s)
      gz.close  
      data.clear
      gz = Zlib::GzipReader.open('png2.tmp')
      data = gz.read
      gz.close
      File.delete('png2.tmp')
      return data
    end
    def make_bitmap_data1
      w = @bitmap.width
      h = @bitmap.height
      data = []
      for y in 0...h
        data.push(0)
        for x in 0...w
          color = @bitmap.get_pixel(x, y)
          data.push(color.red, color.green, color.blue, color.alpha)
        end
      end
      return data.pack('C*')
    end
    def make_iend
      ie_size = [0].pack('N')
      ie_sign = 'IEND'
      ie_crc  = [Zlib.crc32(ie_sign)].pack('N')
      return ie_size + ie_sign + ie_crc
    end
  end
end

#=============================================================================
# ** Bitmap
#=============================================================================
class Bitmap
  def make_png(name = 'like', path = '', mode = 0)
    Zlib::Png_File.open('png.tmp')   { |gz| gz.make_png(self, mode) }
    Zlib::GzipReader.open('png.tmp') { |gz| $read = gz.read }
    f = File.open(path + name + '.png', 'wb')
    f.write($read)
    f.close
    File.delete('png.tmp')
  end
end

Credit



Support


Please post in this topic at RMRK for support.

Known Compatibility Issues

No currently known compatibility issues. The script will be unable to take screenshots in any custom script that makes a scene that does not inherit the update method from Scene_Base however.
Title: Re: Screenshot
Post by: Grafikal on April 05, 2010, 11:37:06 PM
this is badass and way more useful than you think. is there a way to take a screenshot of areas of the map that aren't within the window of VX? Specifically, can you make this puppy screenshot the entire map? If you dig through our guild game, you'll notice an XP version of what i'm talking about. We're using it to build our maps in XP, screenshot the whole map, use the image as a background image in VX and build the game on top of that from VX. Complex, but very cool effect. Curious if this could do the same, but for VX.
Title: Re: Screenshot
Post by: modern algebra on April 06, 2010, 12:53:55 AM
No, it can't take a screenshot of a whole map. Probably wouldn't be too hard to do though, if you want me to.
Title: Re: Screenshot
Post by: Zylos on April 06, 2010, 01:27:50 AM
Modern Algebra, I love you. This is, as grafikal stated, a badass script. :3
Title: Re: Screenshot
Post by: Grafikal on April 06, 2010, 01:38:40 AM
No, it can't take a screenshot of a whole map. Probably wouldn't be too hard to do though, if you want me to.

That would be amazing. If you'd do that, i'd love you more. I don't know how i could do that though. Maybe i'll find a way to get roph to send you nudies.
Title: Re: Screenshot
Post by: modern algebra on April 11, 2010, 12:02:53 AM
Hm, looks like I won't have to: Omegas7 wrote a script to save the map as a picture, so you can send the nudies to him: http://www.rpgmakervx.net/index.php?showtopic=28578

I think he miscredits the PNG Saver script though, unless 66rpg.com is woratana.
Title: Re: Screenshot
Post by: Grafikal on April 11, 2010, 01:04:11 AM
Whoa awesome. Maybe he updated the credits? It looks like Wortana is credited for the PNC Saver Script. Very cool :D
Title: Re: Screenshot
Post by: modern algebra on April 11, 2010, 01:42:35 AM
Yeah, the author of the PNG Saver is 66rpg.com I think, not Woratana.
Title: Re: Screenshot
Post by: Grafikal on April 11, 2010, 01:53:18 AM
ooohhh ok, I thought you had meant the other way around. Well if I get around to use it, I'll have to delve in and check it out.
Title: Re: Screenshot
Post by: CodeMaster on November 23, 2010, 12:34:12 AM
I have a question could you this with a save screen script that shows a picture to show where you are and if I can how would i do it
Title: Re: Screenshot
Post by: Cengiz Han on March 10, 2011, 09:03:03 PM
I can't change destination folder, it saves images to in project folder but I want it save them in graphics\pictures\. :C (sorry for my bad English)
Title: Re: Screenshot
Post by: Cengiz Han on March 10, 2011, 09:08:52 PM
Wow, tried Graphics/Pictures/SS rather than Graphics\Pictures\SS and it is working. Great script, thank you very much... XD
Title: Re: Screenshot
Post by: CodeMaster on March 10, 2011, 09:16:06 PM
There is a edit button you are not supposed to double post.
Title: Re: Screenshot
Post by: brewmeister on March 12, 2011, 05:44:33 PM
There is a 'report' button too. You're not supposed to back-seat moderate!    ;D

<Scratches head> Hmmm, I always thought SephirothSpawn wrote the screenshot.dll ???