scale image

anyone know how to scale and image (up or down) under midp2?

There are 2 solutions :-

Solution 1

  1. create the source image. (Image.createImage(…).
  2. use Image.getRGB(…) to get the pixels from the source image.
  3. scale the RGB pixel array using what-ever scaling algorithm you wish (this is not a J2ME problem)
  4. pass the scaled pixels into Image.createRGBImage(…)

Be warned, a significant number of handsets have faulty implementations of Image.getRGB(…), and there are likely some with faulty Image.createRGBImage(…) implementations too.
However, this is the simpler of the 2 solutions.

Solution 2

  1. Grab the pixel data directly from the raw png data.
  2. Scale the pixel data using what-ever scaling algorithm you wish (this is not a J2ME problem)
  3. regenerate the necessary png wrapper structure.
  4. create the image.

This solution will work on both MIDP1 & 2.
You will need to ensure your source png images store their IDAT chunk uncompressed. (unless you want to write a zlib decompressor too!)
Also, depending on the scaling algorithm you choose for part 2, you may want to impose some restrictions on the color type & bitdepth used in the source image)
You will need to examine the following specifications :-

a) PNG file format specification ( http://www.w3.org/TR/PNG/ )
b) RFC 1950 - ZLIB specification ( http://www.faqs.org/rfcs/rfc1950.html )
c) RFC 1951 - Deflate specification ( http://www.faqs.org/rfcs/rfc1951.html )