Libraries/ImageString
From Ratwiki
Contents |
Overview - Image String package
J2ME devices do support text, but they are usually limited to just one font. For some situations this is too limiting, so to provide a better user experience, this package makes it possible to render text based on images.
Usage
A sequence of image files are created, one for each letter that is to be displayed. An instance of the ImageStringDrawer class is then created which can be used to render text composed of those images to a Graphics object.
Load specific images
Assuming the images h.png, e.png, l.png, o.png, w.png, r.png and d.png were stored in the root directory of the midlet, the following snippet of code would initialise and ImageStringDrawer object and draw "hello world" to the screen.
try {
ImageStringDrawer imageString = new ImageStringDrawer(
"/*.png", new char[] {
'h', 'e', 'l', 'o', 'w', 'r', 'd',
}
);
imageString.draw(g, "hello world", 0, 0, ImageStringDrawer.TOP|ImageStringDrawer.LEFT);
} catch (IOException e) {
// error loading images
}
Load default image set
A second method for initialising an ImageStringDrawer object can be used which will attempt to load images for all printable ASCII characters. When instantiating an ImageStringDrawer object using this method, no exceptions are thrown if the images can't be found, so while this method is easier, it is "less safe".
Assuming the image files are stored in the same location as the previous example, the following would have the same result.
ImageStringDrawer imageString = new ImageStringDrawer("/*.png");
imageString.draw(g, "hello world", 0, 0, ImageStringDrawer.TOP|ImageStringDrawer.LEFT);
Download
| File | Description | Link |
|---|---|---|
| Jar file | Binary package required containing library. | ImageString-1.0.0.jar |
| Source code | Source package containing the J2ME source code, build scripts and javadoc | ImageString-1.0.0-src.zip |
| Javadoc | Javadoc for source code | ImageString-1.0.0-javadoc.zip |