Namespaces
Variants
Actions

How to flip an image in Java ME

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.

SignpostIcon Palette 52.png
Article Metadata

Tested with
Devices(s): Series 40, Series 60

Compatibility
Platform(s): MIDP 2.0

Article
Keywords: Flip, Image, Graphics, Sprite
Created: im2amit (05 Jul 2010)
Updated: tiviinik (18 Jan 2012)
Last edited: hamishwillee (23 Jan 2012)
This page was last modified on 23 January 2012, at 01:07.
162 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved