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"),