Revision as of 08:00, 30 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to flip an image in Java ME

From Nokia Developer 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.*;
import javax.microedition.lcdui.game.*;

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 com.nokia.mid.ui.DirectGraphics.drawImage(javax.microedition.lcdui.Image 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.
99 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.