Image - Loading from buffer

Intro

Most of the time you'll want to load an image from the SD card. This is done easily by just specifying the path of the image based on the location of the boot.[dol|elf| file. That means, if your boot file is in /apps/foo and your image is /apps/foo/bar.png, then
image.LoadImage("/apps/foo/bar.png");
equals to
image.LoadImage("bar.png");

If you're using wiiload, think that the boot file is running from root.

There are some situations however, where you want to load from a buffer. Say, you have a very small application you just want to run very fast. Or maybe you have your own package system where you can extract each file with its own buffer. Anyway, you will need a way to load an image directly, and not through the filesystem.

Preparing the image

If you have your own method for loading something into an unsigned char array, skip this section.

Since you are using devkit, there are some nice tools for you already available. If you look into the devkitPPC/bin folder, there is a tool called raw2c. It can convert any file to a unsigned char buffer. We're going to use this tool. To use it, simply specify you image as an argument when starting the program. Or you could just drag and drop your image onto it. Either way you are presented with a *.c and *.h file. Copy these files into your source folder and include the header file at the point where you want to have access to it. The header file will have one unsigned char[] member, which we will are going to use for loading.

Loading the buffer

libwiisprite assumes that if you're loading a unsigned char array, that it's a buffer. If you're just entering a simple char array ("foo/bar.png") it will assume that it's loading from a path. You can take control over this behaviour with IMG_LOAD_TYPE.

Let's say you converted bar.png with raw2c and included the header file in your source. Now you just need to type the command

image.LoadImage(bar);
and it should load just fine!

Generated on Sun Jun 29 14:29:26 2008 for libwiisprite by  doxygen 1.5.5