PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Screenshot speichern



Cornix
04.12.2009, 22:11
Guten Abend.
Einmal mehr eine kleine Frage im Bezug auf Files. (scheint meine lieblingskategorie zu sein)
Wenn ich vorhabe einen Screenshot zu erstellen, wähle ich alle Sprites von jedem Viewport an und mache einen Blocktransfer der Bitmap Datei jedes Sprites zu einer neuen Bitmap.
Sprich:
Den Background (Tileset/Battleback) alle character sprites, die contents und windowskins von jedem Fenster etc etc.

Soweit so gut, doch wie speichere ich diese neue Bitmap variable nun auf auf dem Rechner? Ich sehe zum Speichern von Werten derzeit nur Marshal.dump welches für RGSS Scripte konzipiert ist.
Wie erstelle ich denn nun einen neue .PNG oder .JPG Datei?

Vielen Dank im Vorraus für alle eure Antworten.
Cornix.

Shining Advances
06.12.2009, 14:49
also google hat mir folgendes script rausgespuckt.
es speichert aber nicht in png/jpg sondern bmp.

#=============================================================================
# *** Aleworks Bitmap(ABMP)
#=============================================================================
# Created by Aleworks(vgvgf)
# Version: 1.00
# Last Modification: 21/04/2007 (day/month/year)
#=============================================================================
#==== Description ====
# This script allows to save a bitmap file(bmp) from the RGSS Bitmap class image.
#=============================================================================
#=============================================================================
#==== Classes & Methods ====
# * Module ABMP
# - Methods
# - ABMP.save(bmp, filename[, background_color[, prevent_hang_up]])
# Saves the 'bmp' image to the filename file. Filename needn't have
# the .bmp extension. If background_color is a Color class, then the saved
# bitmap will have the given color. If it's not given will be nil.
# If prevent_hang_up is true, the script will call Graphics.update each
# 6 seconds aproximately for preventing the game to close by hang up. If
# it is not given, it will be true. You can add a block to the method, that
# will return the completed porcentage of the proccess.
# Note: bitmap images don't support transparency, so all colors that
# have transparency will be writed with full opacity. Also, this is a very
# time consuming method so avoid using it constantly.
# - check_hang_up
# Called internaly for checking if the Graphics need to be updated.
#=============================================================================

#=============================================================================
# ** Module ABMP
#=============================================================================
module ABMP
#---------------------------------------------------------------------------
# * ABMP.save
#---------------------------------------------------------------------------
def self.save(bmp, filename, background_color = nil, prevent_hang_up = true)
if File.extname(filename) != '.bmp'
filename += '.bmp'
end
if !background_color.nil?
temp_bmp = bmp.clone
rect = Rect.new(0, 0, temp_bmp.width, temp_bmp.height)
bmp = Bitmap.new(temp_bmp.width, temp_bmp.height)
bmp.fill_rect(rect, background_color)
bmp.stretch_blt(rect, temp_bmp, rect)
temp_bmp.dispose
Graphics.update if prevent_hang_up
end
file = File.open(filename, 'wb')
file.write('BM')
file.write([54 + (bmp.width * bmp.height * 24) / 8].pack('L'))
file.write('ABMP')
file.write([54].pack('L'))
file.write([40].pack('L'))
file.write([bmp.width].pack('L'))
file.write([bmp.height].pack('L'))
file.write([1].pack('L')[0, 2])
file.write([24].pack('L')[0, 2])
file.write([0, 0, 0, 0, 0, 0].pack('L6'))
null_spaces = 0
if bmp.width / 4 != bmp.width / 4.0
if (bmp.width + 1) / 4 == (bmp.width + 1) / 4.0
null_spaces = 1
elsif (bmp.width + 2) / 4 == (bmp.width + 2) / 4.0
null_spaces = 2
elsif (bmp.width + 3) / 4 == (bmp.width + 3) / 4.0
null_spaces = 3
end
end
time = Time.now
last_porcentage = -1
for y in (-bmp.height + 1)..0
line = ''
for x in 0...bmp.width
color = bmp.get_pixel(x, y.abs)
line += [color.blue.to_i].pack('L')[0, 1]
line += [color.green.to_i].pack('L')[0, 1]
line += [color.red.to_i].pack('L')[0, 1]
time = self.check_hang_up(time) if prevent_hang_up
if block_given?
porcentage = (((y + bmp.height) * bmp.width + x)) * 100
porcentage /= bmp.height * bmp.width
if porcentage > last_porcentage
yield porcentage
last_porcentage = porcentage
end
end
end
file.write(line)
time = self.check_hang_up(time) if prevent_hang_up
end
file.close
end
#---------------------------------------------------------------------------
# * check_hang_up
#---------------------------------------------------------------------------
module_function
def check_hang_up(time)
if time.sec <= Time.now.sec - 6 or time.min != Time.now.min
Graphics.update
return Time.now
end
return time
end
end
credits gehen an vgvgf (steht ja auch im script)

Cornix
06.12.2009, 22:24
Vielen Dank für die Antwort.

Wie ich sehe scheint es aufwendiger zu sein als ich dachte. Ich hatte gehofft es gäbe einen einfacheren Weg.
Ich werde mir, da der Script so wie es scheint sehr auf die Performance schlägt, wohl doch noch einmal durch den Kopf gehen lassen ob ich solch ein Feature in mein Spiel aufnehmen will oder nicht.


Dennoch danke ich für deine Mühe diesen Script für mich zu suchen.
Cornix.