Salva Schermata
Descrizione
E' un semplice sistema per salvare la schermata di gioco in un file png.
Il sistema è basato su uno script che salva un RGSS Bitmap in un file png, senza bisogno di dll.
Questo script era parte di uno script enorme (e poco utile) di XP, non mi stupisco sia passato inosservato ^^
Istruzioni
Mettere lo script in una nuova scheda sotto Materiali
Per salvare la schermata basta usare questo codice in un evento:
salva_schermata("Meraviglia")=> Salva l'immagine in Screens/Meraviglia,png
(Se la cartella Screens non esiste, verrà creata)
Nello script potete specificare la cartella in cui le immagini saranno salvate.
Versione 2.0:
Aggiunta la possibilità di un suffisso composto da data ed orario attuali.
salva_schermata("Meraviglia",true)=> Salva l'immagine in Screens/Meraviglia2012-04-03_17-20-01.png
Per modifiche guardare la documentazione dell'oggetto Time - metodo strftime
(Presto in italiano :) )
Script
#============================================================================== # Salva Schermata # Autore: Keroro - [email protected] # Versione 2.0 # Ultimo aggiornamento 03.04.2012 #============================================================================== # Salva la schermata in un'immagine png nella cartella specificata # # Esempio d'uso da evento: # salva_schermata("Meraviglia") # Se si desiderano giorno ed orario come suffisso: # salva_schermata("Meraviglia",true) # #============================================================================== module Schermata #Ricordati di lasciare / alla fine CARTELLA = "Screens/" #Formato Orario #Guarda documentazione oggetto Time - metodo strftime FORMATO = "%Y-%m-%d_%H-%M-%S" def self.salva(nome,tempo) bitmap = Graphics.snap_to_bitmap unless tempo bitmap.make_png(nome,CARTELLA) else bitmap.make_png(nome+Time.now.strftime(FORMATO),CARTELLA) end bitmap.dispose end end class Game_Interpreter def salva_schermata(nome,tempo=false) Schermata::salva(nome,tempo) end end #============================================================================== # Bitmap to PNG By Cycleby #============================================================================== # # Direct use of the Bitmap object. # bitmap_obj.make_png(name[, path]) # # Name: Save the file name # Path: path to save the # # Thanks 66, Shana, gold Guizi reminder and help! #============================================================================== module Zlib class Png_File < GzipWriter #-------------------------------------------------------------------------- # ? Main #-------------------------------------------------------------------------- def make_png(bitmap_Fx,mode) @mode = mode @bitmap_Fx = bitmap_Fx self.write(make_header) self.write(make_ihdr) self.write(make_idat) self.write(make_iend) end #-------------------------------------------------------------------------- # ? PNG file header block #-------------------------------------------------------------------------- def make_header return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*") end #-------------------------------------------------------------------------- # ? PNG file data block header information (IHDR) #-------------------------------------------------------------------------- def make_ihdr ih_size = [13].pack("N") ih_sign = "IHDR" ih_width = [@bitmap_Fx.width].pack("N") ih_height = [@bitmap_Fx.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 #-------------------------------------------------------------------------- # ? Generated image data (IDAT) #-------------------------------------------------------------------------- def make_idat header = "\x49\x44\x41\x54" case @mode # please 54 ~ when 1 data = make_bitmap_data # 1 else data = make_bitmap_data end data = Zlib::Deflate.deflate(data, 8) crc = [Zlib.crc32(header + data)].pack("N") size = [data.length].pack("N") return size + header + data + crc end #-------------------------------------------------------------------------- # ? Requests from the Bitmap object 54 to generate image data in mode 1 # (please 54 ~) #-------------------------------------------------------------------------- def make_bitmap_data1 w = @bitmap_Fx.width h = @bitmap_Fx.height data = [] for y in 0...h data.push(0) for x in 0...w color = @bitmap_Fx.get_pixel(x, y) red = color.red green = color.green blue = color.blue alpha = color.alpha data.push(red) data.push(green) data.push(blue) data.push(alpha) end end return data.pack("C*") end #-------------------------------------------------------------------------- # ? Bitmap object from the image data generated in mode 0 #-------------------------------------------------------------------------- def make_bitmap_data gz = Zlib::GzipWriter.open('hoge.gz') t_Fx = 0 w = @bitmap_Fx.width h = @bitmap_Fx.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 end if t_Fx % 100000 == 0 s = data.pack("C*") gz.write(s) data.clear #GC.start end color = @bitmap_Fx.get_pixel(x, y) red = color.red green = color.green blue = color.blue alpha = color.alpha data.push(red) data.push(green) data.push(blue) data.push(alpha) end end s = data.pack("C*") gz.write(s) gz.close data.clear gz = Zlib::GzipReader.open('hoge.gz') data = gz.read gz.close File.delete('hoge.gz') return data end #-------------------------------------------------------------------------- # ? PNG end of the file data blocks (IEND) #-------------------------------------------------------------------------- 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 #------------------------------------------------------------------------------ # Related to the Bitmap. #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ? Related #-------------------------------------------------------------------------- def make_png(name="like", path="",mode=0) make_dir(path) if path != "" Zlib::Png_File.open("temp.gz") {|gz| gz.make_png(self,mode) } Zlib::GzipReader.open("temp.gz") {|gz| $read = gz.read } f = File.open(path + name + ".png","wb") f.write($read) f.close File.delete('temp.gz') end #-------------------------------------------------------------------------- # ? Save the path generated #-------------------------------------------------------------------------- def make_dir(path) dir = path.split("/") for i in 0...dir.size unless dir == "." add_dir = dir[0..i].join("/") begin Dir.mkdir(add_dir) rescue end end end end end
Modificato da Keroro, 03 April 2012 - 16:27 PM.