Java examples for javax.microedition.lcdui:Graphics
resize Image Proportional micro edition
import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; public class Main{ public static Image resizeImageProportional(Image sourceImage, int prcSize) { if (prcSize > 100) { prcSize = 100;// w w w. j av a2s . c o m } else if (prcSize <= 0) { return Image.createImage(1, 1); } int imageWidth = sourceImage.getWidth(); int imageHeight = sourceImage.getHeight(); int destWidth = imageWidth * prcSize / 100; int destHeight = imageHeight * prcSize / 100; /** Buffers **/ int[] rgbData = new int[imageWidth * imageHeight]; int[] rgbDest = new int[destWidth * destHeight]; /** Fill buffer **/ sourceImage.getRGB(rgbData, 0, imageWidth, 0, 0, imageWidth, imageHeight); int currY, xx, yy = 0; for (int y = 0; y < destHeight; y++) { currY = y * destWidth; xx = 0; for (int x = 0; x < destWidth; x++) { try { rgbDest[currY + x] = rgbData[(yy * 100 + xx) / 100]; } catch (Throwable ex) { } xx += 10000 / prcSize; } yy = (y * imageHeight / destHeight) * imageWidth; } return Image.createRGBImage(rgbDest, destWidth, destHeight, false); } }