JSR-234 1.1

javax.microedition.amms.control.imageeffect
Interface ImageTransformControl

All Superinterfaces:
javax.microedition.media.Control, EffectControl

public interface ImageTransformControl
extends EffectControl

ImageTransformControl is used to crop, zoom, mirror, flip, stretch and rotate images. The application may specify a source rectangle that is mapped to a new image whose size may be specified.

Initially, the source rectangle consists of the whole image and the target image size is equivalent to the original size. So, if these rectangles are not altered, the control does not modify the image in any way. The size of the original image can be queried by getSourceWidth and getSourceHeight methods.

The tranformation is modeled so that the processed image is placed on top of a very large black image. The upper left corner of the processed image is in (0,0) and the lower right corner is in (width-1,height-1). setSourceRect takes the starting point coordinates and the width and height vector of the area that is intended to be transformed. A negative width and/or height will flip the image vertically and/or horisontally. The source area can contain black pixels outside the processed image.

flipped image
For clarity, the black pixels outside the processed image are grey in this figure.

After the stretching operation, the resulting image may be rotated by a multiple of 90 degrees.

Examples

Needed variables are initialized as follows. processor is the MediaProcessor the input has been set.
 String controlName = "javax.microedition.amms.control.imageeffect.ImageTransformControl";
 ImageTransformControl transform = processor.getControl(controlName);
 int origWidth = transform.getSourceWidth();
 int origHeight = transform.getSourceHeight();
 
Adding frames
 // add 50 pixel wide black frames around the picture
 transform.setSourceRect( -50, -50, origWidth + 2 * 50, origHeight + 2 * 50);
 transform.setTargetSize( origWidth + 2 * 50, origHeight + 2 * 50, 0);
 

50 pixel wide empty frames

OverlayControl could be used to add nicer looking frames on top of the produced black frames.
Stretching
 // stretch to 100 * 100 pixels bigger image by setting the target width and height to original + 100
 transform.setSourceRect( 0, 0, origWidth, origHeight);
 transform.setTargetSize( origWidth + 100, origHeight + 100, 0);
 

stretched image

Flipping
 // for vertical flip y = origHeight and height is negative
 transform.setSourceRect( 0, origHeight, origWidth, -origHeight);
 transform.setTargetSize( 0, 0, 0); // using 0 as width and height retain the original image size
 

flipped image


Field Summary
 
Fields inherited from interface javax.microedition.amms.control.EffectControl
SCOPE_LIVE_AND_RECORD, SCOPE_LIVE_ONLY, SCOPE_RECORD_ONLY
 
Method Summary
 int getSourceHeight()
          Returns the height of the source image.
 int getSourceWidth()
          Returns the width of the source image.
 void setSourceRect(int x, int y, int width, int height)
          Specifies the source rectangle in pixels.
 void setTargetSize(int width, int height, int rotation)
          Specifies the size and rotation of the resulting image.
 
Methods inherited from interface javax.microedition.amms.control.EffectControl
getPreset, getPresetNames, getScope, isEnabled, isEnforced, setEnabled, setEnforced, setPreset, setScope
 

Method Detail

getSourceWidth

int getSourceWidth()
Returns the width of the source image.

Returns:
the width of the source image
Throws:
java.lang.IllegalStateException - if the source image is not set

getSourceHeight

int getSourceHeight()
Returns the height of the source image.

Returns:
the height of the source image
Throws:
java.lang.IllegalStateException - if the source image is not set

setSourceRect

void setSourceRect(int x,
                   int y,
                   int width,
                   int height)
Specifies the source rectangle in pixels. The rectangle will consist of pixels (x,y)-(x+|width|-1,y+|height|-1). Use negative values for width and height to mirror or swap the image.

The default source rectangle is the source image. Therefore, the call of setSourceRect can be omitted if the parameters would be (0, 0, original_width, original_height).

Parameters:
x - the x-coordinate of the upper left corner of the rectangle
y - the y-coordinate of the upper left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
Throws:
java.lang.IllegalArgumentException - if width or height is 0

setTargetSize

void setTargetSize(int width,
                   int height,
                   int rotation)
Specifies the size and rotation of the resulting image. The width and height of the resulting image mean the dimensions of the image before rotation. If rotated for example 90 degrees, the size of the image after rotation is height x width instead of width x height.

The default target size is the size specified with setSourceRect and the default target rotation is zero degrees. Therefore, the call of setTargetSize can be omitted if the operation to be performed is not shrink, stretch or rotate.

Parameters:
width - the width of the resulting image. If 0 the width of the source image is used.
height - the height of the resulting image. If 0 the height of the source image is used.
rotation - the rotation of the resulting image, in multiples of 90 degrees. Positive angles designate clockwise rotation and negative values designate counterclockwise rotation.
Throws:
java.lang.IllegalArgumentException - if width or height is negative or if they are above certain device-specific limits or if the rotation angle is not an integer multiple of 90 degrees

JSR-234 1.1

Copyright © 2004-2007 Nokia Corporation. See the Copyright for details.