Namespaces

Variants
Actions

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 over the next few weeks. 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.

Contents

Solution

  • 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

Imports

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);
}


Note

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.
95 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.

×