Bitmap.new(path) loads the file and creates a bitmap out of it.
It knows how to load from the encrypted archive as well.
If I give it a path to a custom encrypted archive, how could I load that?
Would I need to write the actual bitmap loading code myself? I can give it a bytestring containing the image file data (png, jpg, tga, bmp, etc.), but it doesn't know how to load raw data.
Actually this reminds me of the audio loading problem, though not quite the same.
I think you'd need to write your own, I also tried giving it the raw data from an encrypted image file but yeah, it won't load it. It still needs it to be a valid image file.
Creating the image before loading seems to work though, and you can also even just recreate them all using the same file name so that only the last loaded image will have an actual file.
so like
def self.create_temp(filename) content = get_packed(filename) temp = File.open("Data.png","wb") content.each {|x| temp.write(x)} temp.close return "Data.png" end def self.try @spr = Sprite.new @spr.bitmap = Bitmap.new(create_temp("Attack1.data")) @spr.z = 9999 @spr2 = Sprite.new @spr2.y = 300 @spr2.z = 9998 @spr2.bitmap = Bitmap.new(create_temp("Attack2.data")) endhere, create_temp creates an image file from the supplied encrypted file... And every call of it will just overwrite the old file so only 1 file exists. get_packed is a custom method that returns the raw data from the encrypted file.It's not really optimal but at the very least it works and just keeps 1 extracted file instead of having everything extracted and available...
PS: I think we could call a delete file afterwards to remove the temp file...
But of course if we can find a not so cumbersome method that removes he need for a temp file, that would be nice.
Given that the Bitmap format is known, we could potentially build the bitmap ourselves.
Using libraries such as libpng, libjpg, and other libraries we could use them to load the images and then construct the bitmaps.
We could then even take it further and add support for other image formats.
Yeah we could do that too. My method above is just one for those who don't know how to load the bitmaps manually (like me) XD
You could also modify the way the cache loads unchached bitmaps to use the method I posted above, so that once a bitmap is loaded, it still stays in the cache... as far as my tests are concerned, after creation of the bitmap, you can safely delete the temporary image file.