www.chrfr.de

Creating images from pixel data in arrays

MIDP 1.0 allows to create blank images, to copy existing images, or to decode images from a resource representing a supported image file format such as PNG (providing either the resource name as a string or the resource data in an array). It does not directly allow to create an image from pixel data in an RGB or RGBA array. A rather obvious approach to create an image from pixel data in an array would be to create a mutable image and call setColor and drawRect once for each pixel. However, that would be rather inefficient and it wouldn't work with transparency.

We can do much better if we use the one method MIDP 1.0 offers for creating an image from data in memory. Since this happens to expect the data in PNG format, we just have to provide it in PNG format. This task is less formidable than it may sound, because we only need to implement a minimal PNG encoder.

Back to MIDP page


Copyright (C) 2006-2013 by Christian Fröschlin. Please note the legal disclaimer. If you experience problems with this page, contact webmaster@chrfr.de.