HOME DEMOS TUTORIAL DEVKIT GITHUB

Images

Image files may be loaded by calling ra.loadImage with the path to the file. Since raster.js acts like an 8-bit system, it will downsample photographic images so that they use less colors and are compatible with the palette.

Depending upon the environment, an image may be loaded immediately (like in node.js), or it may be loaded asynchronously (like on the web). To keep code portable, you can wait until all images have loaded by using ra.then. Once loaded, an image can be drawn by using ra.paste.

const ra = require('raster'); ra.setZoom(2); let img = ra.loadImage('img/my_background.png'); ra.then(() => { ra.paste(img); ra.run(); });

If the size of the field has not been set, and the colorMap has not been explicitly assigned, a call to ra.paste will also handle these, by setting the field to match the loaded image and creating a compatible colorMap.

Previous: Text Table of Contents Next: Scrolling