Saving Bitmaps as Files
[SIZE=2]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:
[/SIZE][SIZE=2]
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:
[/SIZE][SIZE=2]
Just a little trick someone might find some use for (I will be soon. ;))
[/SIZE]
[SIZE=2]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
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
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
Expand to see the code.
It is fairly simple to use:
To save a bitmap, simply use:
[/SIZE]
[SIZE=4][SIZE=2]BitmapDump.[/SIZE][/SIZE][SIZE=4][SIZE=2]save_bitmap(bitmap, filename)[/SIZE][/SIZE]
Expand to see the code.
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:
[/SIZE]
[SIZE=4][SIZE=2]bitmap = BitmapDump.read_bitmap(filename)[/SIZE][/SIZE]
Expand to see the code.
Just a little trick someone might find some use for (I will be soon. ;))
[/SIZE]