07-26-2005, 01:00 PM
Saving Bitmaps as Files
SephirothSpawn
Aug 17 2006
Ok, this isn't as much as a script as it is a tool to save bitmaps as data, then recover them later. It was nothing more than 10 minutes of working with the get_pixel and set_pixel methods. Anyways, here's the mini-code
It is fairly simple to use:
To save a bitmap, simply use:
It will then save the bitmap as data in your game folder. I would make a new folder called Bitmap Data or something and have stuff save there, but that may just be me.
To Recover Saved Bitmap, use:
Just a little trick someone might find some use for (I will be soon.
SephirothSpawn
Aug 17 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.
No support is given.
Ok, this isn't as much as a script as it is a tool to save bitmaps as data, then recover them later. It was nothing more than 10 minutes of working with the get_pixel and set_pixel methods. Anyways, here's the mini-code
Code:
module BitmapDump
def self.save_bitmap(bitmap, filename)
red = Table.new(bitmap.width, bitmap.height)
green = Table.new(bitmap.width, bitmap.height)
blue = Table.new(bitmap.width, bitmap.height)
alpha = Table.new(bitmap.width, bitmap.height)
for i in 0...bitmap.width
for j in 0...bitmap.height
color = bitmap.get_pixel(i, j)
red[i, j] = color.red
green[i, j] = color.green
blue[i, j] = color.blue
alpha[i, j] = color.alpha
end
end
file = File.open("#{filename}.rxdata", 'wb')
Marshal.dump([red, green, blue, alpha], file)
file.close
end
def self.read_bitmap(filename)
file = File.open("#{filename}.rxdata", 'rb')
colors = Marshal.load(file)
file.close
red, green, blue, alpha = colors[0], colors[1], colors[2], colors[3], colors[4]
bitmap = Bitmap.new(red.xsize, red.ysize)
for i in 0...bitmap.width
for j in 0...bitmap.height
bitmap.set_pixel(i, j, Color.new(red[i, j], green[i, j], blue[i, j], alpha[i, j]))
end
end
return bitmap
end
end
It is fairly simple to use:
To save a bitmap, simply use:
Code:
BitmapDump.save_bitmap(bitmap, filename)
It will then save the bitmap as data in your game folder. I would make a new folder called Bitmap Data or something and have stuff save there, but that may just be me.
To Recover Saved Bitmap, use:
Code:
bitmap = BitmapDump.read_bitmap(filename)
Just a little trick someone might find some use for (I will be soon.