Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to flip an image in Java ME

From Wiki
Jump to: navigation, search

This articles shows how to to flip a given Image in Java ME.



  • Create a new Image using createImage
  • Or use drawRegion to fllp the image when drawn.
  • Apply Mirror transformation using Sprite.TRANS_MIRROR

On some devices, pre-transformed images may render more quickly than images that are transformed on the fly using drawRegion. However, creating such images does consume additional heap space, so this technique should be applied only to images whose rendering speed is critical.

Sample Code


import javax.microedition.lcdui.*;

Flip Image

Create a new flipped image with createImage. For immutable source images, transparency information, if any, is copied to the new image unchanged.

public Image flip(Image source)
return Image.createImage(source,0, 0, source.getWidth(), source.getHeight(), Sprite.TRANS_MIRROR);

Or use drawRegion to fllp the image when drawn.

public void drawFlippedImage(Graphics g, Image source)
g.drawRegion(source, 0, 0, source.getWidth(), source.getHeight(), Sprite.TRANS_MIRROR, 0, 0, Graphics.TOP | Graphics.LEFT);


For MIDP 1.0 devices we can use img, int x, int y, int anchor, int manipulation) with manipulation = DirectGraphics.FLIP_HORIZONTAL

--Submitted by Amitabh Srivastava at 16:55(IST), 5 July 2010.

Article Metadata
Tested withCompatibilityArticle
Created: im2amit (05 Jul 2010)
Updated: tiviinik (18 Jan 2012)
Last edited: hamishwillee (30 Jul 2013)
This page was last modified on 30 July 2013, at 08:00.
48 page views in the last 30 days.