Scaling and rotating bitmaps on BlackBerry

Included in the SDK is the ImageManipulator class that RIM provides in one of their KB articles. With it you can scale and rotate Bitmaps and paint them directly to an existing Graphics object. This allows you to get around the "white background" issue you would normally get when painting a manipulated image on to a new Bitmap object since new Bitmaps always start with an opaque white background.

// this object can be shared so you do not need to create a new one each time
ImageManipulator imageManipulator = new ImageManipulator();

// set the bitmap, angle and then apply the transformation
// this can happen on a background thread like a TimerTask
imageManipulator.setBitmap( bitmap );
imageManipulator.transformByAngle( angle, false, false );
imageManipulator.applyTransformation();

// paint the transformed bitmap
// transformAndPaintBitmap() will not call applyTransformation() a second time
graphics.pushContext( graphics.getClippingRect(), 0, 0 );
graphics.translate( bitmapX, bitmapY );
imageManipulator.transformAndPaintBitmap( graphics );
graphics.popContext();
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Feb 02, 2011

    Mark McEver says:

    How high is the quality of transformations using this method? I'm curious since...

    How high is the quality of transformations using this method? I'm curious since the EncodedImage class's scaling algorithm is pretty horrible.

    1. Feb 02, 2011

      Martin Reed says:

      I haven't used it for scaling yet actually, just rotating.

      I haven't used it for scaling yet actually, just rotating.

© 2011 Metova, Inc.