Just An Application

July 22, 2009

What’s New In MIDP 3.0 ? Part 30: LCDUI – ScalableImage

Filed under: Java, JME — Tags: , , , , , , — Simon Lewis @ 1:15 pm

1. ScalableImage

The ScalableImage class is a sub-class of the Image class.

A ScalableImage represents a scalable vector graphics based Image.

An instance of ScalableImagecan be used anywhere an Image can be used, although an implementation may choose not to support animation or user interaction if specified in the underlying image.

2. Creating A ScalableImage From Data

A ScalableImage can be created from data in SVG Tiny 1.1 format using any of the following Image method’s


    public static Image createImage(java.io.InputStream stream)
                        throws 
                            java.io.IOException

    public static Image createImage(String name)
                        throws 
                            java.io.IOException
						 
    public static Image createImage(byte[] imageData, int imageOffset, int imageLength)

In each case the resulting Image can then be cast to an ScalableImage.

Whether the resulting Image is in fact an ScalableImage can be determined by calling the Image’s isScalable() method.

3. Creating A ScalableImage From An External SVG Based Image

A ScalableImage can be created from an accessible image from an external SVG based API by using the ScalableImage method

    public static ScalableImage bind(Object extScalableImage)

The resulting ScalableImage will be bound to the external image specified by the extScalableImage argument.

Any changes made to the external image will be visible in the ScalableImage bound to it.

An example of a external SVG based API is the Scalable 2D Vector Graphics API for J2ME (JSR226).

In this case the extScalableImage argument would specify an instance of

     javax.microedition.m2g.ScalableImage

4. Getting The Viewport Dimensions

The width and height of the viewport defined for the underlying image can be obtained by calling the ScalableImage’s

    public int getViewportWidth()

and

    public int getViewportHeight()

methods respectively.

5. Setting The Size

The width and height of a ScalableImage when rasterized and rendered as a low-level pixel based Image can be set by using the ScalableImage’s

    public void setWidth(int width, boolean matchAspectRatio)

and

    public void setHeight(int height, boolean matchAspectRatio)

methods respectively.

The width and height arguments are in pixels,

It is an error if the dimension specified is less than one and an IllegalArgumentException will be thrown.

In each case if the matchAspectRatio argument is true then the other dimension is adjusted automatically to preserve the aspect ratio as defined by the underlying image’s viewport.

6. Unbinding A Scalable Image

A ScalableImage which was created by the ScalableImage.bind(Object) method can be unbound from the external image by calling the ScalableImage’s

    public void unbind()

Following the method call any changes made to the external image to which the ScalableImage was originally bound will no longer be visible in the ScalableImage itself.

If the ScalableImage is not bound to an external image then the method has no effect.


Copyright (c) 2009 By Simon Lewis. All Rights Reserved.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: