// Scale the original Bitmap into the new Bitmap using
// a Lanczos filter.
bitmapOrig.scaleInto(bitmapScaled, Bitmap.FILTER_LANCZOS);
// Display the original Bitmap on the screen
final BitmapField bitmapFieldOrig =
new BitmapField(bitmapOrig, Field.FOCUSABLE);
final StringBuffer strBuff = new StringBuffer("Original - ");
strBuff.append(bitmapOrig.getWidth());
strBuff.append(LABEL_X);
strBuff.append(bitmapOrig.getHeight());
add(new LabelField(strBuff.toString()));
add(bitmapFieldOrig);
add(new SeparatorField());
// Display the scaled Bitmap on the screen
final BitmapField bitmapFieldScaled1 =
new BitmapField(bitmapScaled, Field.FOCUSABLE);
strBuff.delete(0, strBuff.length());
strBuff.append("\nScaled - ");
strBuff.append(bitmapScaled.getWidth());
strBuff.append(LABEL_X);
strBuff.append(bitmapScaled.getHeight());
strBuff.append(" - FILTER_LANCZOS - Aspect ratio not preserved");
add(new LabelField(strBuff.toString()));
add(bitmapFieldScaled1);
add(new SeparatorField());
// Redefine the scaled Bitmap
bitmapScaled =
new Bitmap(Bitmap.ROWWISE_32BIT_ARGB8888, scaledX, scaledY);
// Scale the original Bitmap into the new Bitmap using
// a bilinear filter and maintaining aspect ratio.
bitmapOrig.scaleInto(bitmapScaled, Bitmap.FILTER_BILINEAR,
Bitmap.SCALE_TO_FILL);
// Display the newly scaled Bitmap on the screen
final BitmapField bitmapFieldScaled2 =
new BitmapField(bitmapScaled, Field.FOCUSABLE);
strBuff.delete(0, strBuff.length());
strBuff.append("\nScaled - ");
strBuff.append(bitmapScaled.getWidth());
strBuff.append(LABEL_X);
strBuff.append(bitmapScaled.getHeight());
strBuff.append(" - FILTER_BILINEAR - Aspect ratio preserved");
add(new LabelField(strBuff.toString()));
add(bitmapFieldScaled2);
add(new SeparatorField());
// Redefine the scaled Bitmap
bitmapScaled =
new Bitmap(Bitmap.ROWWISE_32BIT_ARGB8888, scaledX, scaledY);
// Calculate fragment dimensions
final int fragmentWidth = bitmapOrig.getWidth() >> 1; // >> 1
// equivalent
// to / 2
final int fragmentHeight = bitmapOrig.getHeight() >> 1; // >> 1
// equivalent
// to / 2
// Scale a fragment of the original Bitmap into the new Bitmap
// using a box filter.
bitmapOrig.scaleInto(0, 0, fragmentWidth, fragmentHeight,
bitmapScaled, 0, 0, bitmapScaled.getWidth(), bitmapScaled
.getHeight(), Bitmap.FILTER_BOX);
// Display the newly scaled Bitmap on the screen
final BitmapField bitmapFieldScaled3 =
new BitmapField(bitmapScaled, Field.FOCUSABLE);
strBuff.delete(0, strBuff.length());
strBuff.append("\nScaled fragment ");
strBuff.append(fragmentWidth);
strBuff.append(LABEL_X);
strBuff.append(fragmentHeight);
strBuff.append(" into ");
strBuff.append(bitmapScaled.getWidth());
strBuff.append(LABEL_X);
strBuff.append(bitmapScaled.getHeight());
strBuff.append(" - FILTER_BOX");
add(new LabelField(strBuff.toString()));
add(bitmapFieldScaled3);
// Add a menu item to display an animation in a popup screen
final MenuItem showAnimation =
new MenuItem(new StringProvider("Show Animation"),
0x230010, 0);
showAnimation.setCommand(new Command(new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
// Create an EncodedImage object to contain an animated
// gif resource.
final EncodedImage encodedImage =
EncodedImage
.getEncodedImageResource("animation.gif");
// Create a BitmapField to contain the animation
final BitmapField bitmapFieldAnimation = new BitmapField();
bitmapFieldAnimation.setImage(encodedImage);
// Push a popup screen containing the BitmapField onto the
// display stack.
UiApplication.getUiApplication().pushScreen(
new BitmapDemoPopup(bitmapFieldAnimation));