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.

Revision as of 09:49, 6 October 2013 by kiran10182 (Talk | contribs)

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

Image processing showcase using the AMMS API in Java ME

From Wiki
Jump to: navigation, search
Featured Article
06 Oct
2013

This article shows some of the image effects achievable using the AMMS API on the Asha software platform.

Article Metadata
Code ExampleTested with
Devices(s): Nokia Asha SDK 1.0 (beta) Emulator
CompatibilityArticle
Created: jappit (17 Jul 2013)
Last edited: kiran10182 (06 Oct 2013)

Contents

Introduction

The Asha software platform introduces support for several new features of the AMMS API, allowing to perform image processing with few lines of code. A complete introduction of how these new features can be used in a Java app is available here: Image processing using Java ME.

This article shows how to achieve specific effects, including the predefined chromatic effects to more complex transformations.

Image effects

The ImageEffectControl has five available presets on the Asha software platform, that can be used to apply chromatic effects to images.

Applying effects can be achieved, as explained here, by obtaining a reference to the ImageEffectControl instance and applying the desired effects via its setPreset method.

MediaProcessor mp = GlobalManager.createMediaProcessor("image/jpeg");
 
ImageEffectControl effectControl = (ImageEffectControl)mp.getControl("javax.microedition.amms.control.imageeffect.ImageEffectControl");
 
effectControl.setPreset(preset);

The available effects are shown below.

Original image
Emboss
effectControl.setPreset("emboss");
Monochrome
effectControl.setPreset("monochrome");
Negative
effectControl.setPreset("negative");
Sepia
effectControl.setPreset("sepia");
Solarize
effectControl.setPreset("solarize");


Note.pngNote: Available presets can be queried at runtime by using the getPresetNames() method

Image transformations

Image transformations, as explained in the Image processing using Java ME article, can be applied to images by similarly obtaining a reference to the ImageTransformControl instance, and the specifying:

MediaProcessor mp = GlobalManager.createMediaProcessor("image/jpeg");
 
ImageTransformControl transformControl = (ImageTransformControl)mp.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");
 
transformControl.setSourceRect(sourceX, sourceY, sourceWidth, sourceHeight);
 
transformControl.setTargetSize(targetWidth, targetHeight, rotation);

With those two methods, multiple effects can be achieved, including the ones illustrated below.

Image rotate
transformControl.setSourceRect(
0, 0, photoWidth, photoHeight
);
transformControl.setTargetSize(
photoWidth, photoHeight, 90
);
Image reduce
transformControl.setSourceRect(
0, 0, photoWidth, photoHeight
);
transformControl.setTargetSize(
photoWidth / 2, photoHeight / 2, 0
);
Image crop
transformControl.setSourceRect(
0, 0, photoWidth / 2, photoHeight / 2
);
transformControl.setTargetSize(
photoWidth / 2, photoHeight / 2, 0
);
Image stretch
transformControl.setSourceRect(
0, 0, photoWidth, photoHeight
);
transformControl.setTargetSize(
photoWidth, photoHeight * 2, 0
);
Image mirror
transformControl.setSourceRect(
0, photoHeight, photoWidth, -photoHeight
);
transformControl.setTargetSize(
photoWidth, photoHeight, 0
);
Image frame
int frameSize = 30;
transformControl.setSourceRect(
-frameSize, -frameSize,
photoWidth + 2 * frameSize, photoHeight + 2 * frameSize
);
transformControl.setTargetSize(
photoWidth, photoHeight, 0
);

Image overlays

AMMS allows to set image overlays by using the OverlayControl: once obtained a reference to that, the overlay can be set via its insertImage method.

MediaProcessor mp = GlobalManager.createMediaProcessor("image/jpeg");
 
OverlayControl overlayControl = (OverlayControl)mp.getControl("javax.microedition.amms.control.imageeffect.OverlayControl");
 
overlayControl.insertImage(overlayImage, overlayX, overlayY, int zOrder);

The samples below show how the same image can be set as overlay multiple times, or how different images can be set as overlays.

Multiple overlays with a single image
Image overlay = Image.createImage("/overlay0.png");
 
for(int i = 0; i < objects; i++)
{
overlayControl.insertImage(overlay, 10 + 50 * i, 20, 0, 0x00ffff00);
}
Multiple overlays with different images
Image overlay = null;
 
for(int i = 0; i < objects; i++)
{
overlay = Image.createImage("/overlay" + i + ".png");
 
overlayControl.insertImage(overlay, 10 + 50 * i, 20, 0, 0x00ffff00);
}

Note.pngNote: When reusing an OverlayControl instance, it is important to call its clear() method to remove any previously inserted image overlay

Further processing possibilities

The following sections show how to achieve specific effects by combining multiple processing controls or by using specific settings for a defined effect control.

Combined effects

The processing techniques illustrated above can be easily combined to produce resulting images with chromatic effects, transformations and image overlays, as the sample below shows.

Flipped image with negative effect and two overlays applied
effectControl.setPreset("negative");
 
transformControl.setSourceRect(0, photoHeight, photoWidth, -photoHeight);
transformControl.setTargetSize(photoWidth, photoHeight, 0);
 
overlayControl.insertImage(overlay1, 10, 20, 0, 0x00ffff00);
overlayControl.insertImage(overlay2, 60, 20, 0, 0x00ffff00);

Applying effects to overlays

As shown in the previous section, chromatic effects are applied to the input image only, without the overlays being processed by those effects.

In order to apply an effect to an image with all its applied overlay, it is necessary to perform a 2-step processing:

  1. in the first step the image is processed by applying the overlay
  2. when the first processing its complete, the resulting image is used as input for a second processing, where the image effects are applied

Using the sample illustrated above, and assuming the MediaProcessor output is set to a ByteArrayOutputStream:

overlayControl.insertImage(overlay1, 10, 20, 0, 0x00ffff00);
overlayControl.insertImage(overlay2, 60, 20, 0, 0x00ffff00);
 
mediaProcessor.complete();
 
byte[] imageBytes = outputStream.toByteArray();
Image processedPhoto = Image.createImage(imageBytes, 0, imageBytes.length);
 
mediaProcessor.setInput(processedImage);
effectControl.setPreset("negative");
Image effects also applied to overlays

Squared thumbnails

Squared thumbnails can be generated using the ImageTransformControl, as shown by the following code snippet, that takes the central portion of the input image, and resizes that accordingly to the desired thumbnail size.

int thumbSize = sizeGauge.getValue();
 
int squareSize = Math.min(photoWidth, photoHeight);
 
transformControl.setSourceRect((photoWidth - squareSize) / 2, (photoHeight - squareSize) / 2, squareSize, squareSize);
transformControl.setTargetSize(thumbSize, thumbSize, 0);
Squared thumbnail generation

Summary

This article showcases some of the effects achievable by using the AMMS API.

For an introduction to the usage of MediaProcessor, a reference article is available: Image processing using Java ME.

Full source code of the Java app implemented in this article is available here: Media:WikiAshaImageProcessing.zip.

This page was last modified on 6 October 2013, at 09:49.
214 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.

×