Here's what I do to scale an image. There may be an easier way to do it by percentage of original image size, but I haven't found it.
Hope this helps.
EncodedImage bitmap = null;
String path = "/classpath/to/image.png";
InputStream in = ThisClass.class.getResourceAsStream(path);
byte[] data = new byte[in.available()];
in.read(data);
bitmap = EncodedImage.createEncodedImage(data, 0, data.length);
int divisor = Fixed32.toFP(100);
/**
* Change this number, < 100 makes the image bigger by
* percentage. i.e. 90 makes the image 110% normal size.
* By increasing, you will reduce the image size,
* e.g. 110 makes the image 90% normal size.
*/
int multiplier = Fixed32.toFP(110);
int fixedX = Fixed32.toFP(1);
/** First, divide the image scale by 100. */
fixedX = Fixed32.div(fixedX,divisor);
/** Now, multiply the image scale by the multiplier. */
fixedX = Fixed32.mul(fixedX,multiplier);
int fixedY = Fixed32.toFP(1);
fixedY = Fixed32.div(fixedY,divisor);
fixedY = Fixed32.mul(fixedY,multiplier);
bitmap = bitmap.scaleImage32(fixedX,fixedY);
in.close();
BitmapField bmp = new BitmapField();
bmp.setImage(bitmap);
|