public ImageDisplayScreen(EncodedImage image) { int displayWidth = Fixed32.toFP(Display.getWidth()); int imageWidth = Fixed32.toFP(image.getWidth()); int scalingFactor = Fixed32.div(imageWidth, displayWidth); EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor); BitmapField bitmapFiled = new BitmapField(); bitmapFiled.setImage(scaledImage); add(bitmapFiled); }
public Bitmap scaleImage(EncodedImage encodedImage, int requiredWidth, int requiredHeight) { int currentWidth = Fixed32.toFP(encodedImage.getWidth()); int currentHeight = Fixed32.toFP(encodedImage.getHeight()); int scaleXFixed32 = Fixed32.div(currentWidth, requiredWidth); int scaleYFixed32 = Fixed32.div(currentHeight, requiredHeight); EncodedImage image = encodedImage.scaleImage32(scaleXFixed32, scaleYFixed32); return image.getBitmap(); }
public EncodedImage getScaledImage(EncodedImage ei, int wsize) { EncodedImage image = ei; if (wsize != 0) { int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); int factor = Fixed32.div(wsize, image.getWidth()); int height = Fixed32.mul(image.getHeight(), factor); int scaleXFixed32 = Fixed32.div(currentWidthFixed32, Fixed32.toFP(wsize)); int scaleYFixed32 = Fixed32.div(currentHeightFixed32, Fixed32.toFP(height)); image = ei.scaleImage32(scaleXFixed32, scaleYFixed32); } return image; }
// Resize a bitmap proportionally (shrink or enlarge) to make it fit a maxX x maxY rectangle public static Bitmap getFitBitmapImage(String imagename, int maxX, int maxY) { EncodedImage image = EncodedImage.getEncodedImageResource(imagename); int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); // double ratio = (double)ratioX / (double) ratioY; double rx = (double) image.getWidth() / (double) maxX; double ry = (double) image.getHeight() / (double) maxY; double r = 0; if (rx > ry) r = rx; else r = ry; double w = (double) image.getWidth() / r; double h = (double) image.getHeight() / r; int width = (int) w; int height = (int) h; int requiredWidthFixed32 = Fixed32.toFP(width); int requiredHeightFixed32 = Fixed32.toFP(height); int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32); int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32); image = image.scaleImage32(scaleXFixed32, scaleYFixed32); return image.getBitmap(); }
// Resize a bitmap proportionally (shrink or enlarge) by a ratio factor public static Bitmap getScaledBitmapImage(String imagename, double ratio) { EncodedImage image = EncodedImage.getEncodedImageResource(imagename); int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); double w = (double) image.getWidth() * ratio; double h = (double) image.getHeight() * ratio; int width = (int) w; int height = (int) h; int requiredWidthFixed32 = Fixed32.toFP(width); int requiredHeightFixed32 = Fixed32.toFP(height); int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32); int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32); image = image.scaleImage32(scaleXFixed32, scaleYFixed32); return image.getBitmap(); }