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 create a magnifying lens application in Asha platform

From Wiki
Jump to: navigation, search
Featured Article
09 Feb

This article explains how to create a magnifying lens application for the Asha platform.

Note.pngNote: This article was an entry in the Nokia Asha Wiki Competition 2013H2.

Article Metadata
Code ExampleCompatibilityArticle
Created: jsivaguru (15 Dec 2013)
Last edited: jsivaguru (10 Feb 2014)


We will use the Asha platform's excellent image processing capabilities to make a magnifying glass application.

We will create an application that magnifies a portion of a still image by applying cropping and scaling techniques. Note that the platform does not permit magnification of a live feed from the camera.

Magnification application


The core of the magnification logic is in the following code.

This is the pointer pressed method of an image added to a Form.

Whenever the user clicks on a particular location in an image, we create a fixed size rectangle that includes the selected pixel. We use the transform control in the Advanced Multimedia Supplements (AMMS) APIs to crop the image. That gives us a rectangular area that surrounds the selected pixel.

We then use the AMMS APIs again to scale the rectangular region to the required magnification level.

               int sub_value_x = this.getAbsoluteX() + this.getStyle().getPadding(Component.LEFT);
int sub_value_y = this.getAbsoluteY() + this.getStyle().getPadding(Component.TOP);
// We are choosing a point that is diagonally across from the pointer pressed location.
sourceX = ((2 * (x) - length_rect) / 2) - sub_value_x;
sourceY = ((2 * (y) - breadth_rect) / 2) - sub_value_y;
int targetWidth = breadth_rect;
int targetHeight = length_rect;
//Transforming to required size
transformControl.setSourceRect(sourceX, sourceY, breadth_rect, length_rect);
transformControl.setTargetSize(targetWidth, targetHeight, 0);
// Setting input
} catch (MediaException ex)
//Setting output
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// Performing the scale for the first time
} catch (MediaException ex)
byte[] b = bos.toByteArray();
// Higher levels of scale for zoom factor greater than one.
if (zoomfactor > 1)
mp.setInput(javax.microedition.lcdui.Image.createImage(b, 0, b.length));
bos = new ByteArrayOutputStream();
transformControl.setSourceRect(0, 0, length_rect, breadth_rect);
// The target width and height is in multiples of the zoom factor.
int targetW = (int) (zoomfactor * breadth_rect);
int targetH = (int) (zoomfactor * length_rect);
transformControl.setTargetSize(targetW, targetH, 0);
b = bos.toByteArray();
} catch (MediaException ex)
// Creating the scaled(Magnified) image.
magnified_image = Image.createImage(b, 0, b.length);
top.addComponent(new Label(magnified_image));


This article demonstrates how to use the Asha Platform's camera as a magnifying lens.

This page was last modified on 10 February 2014, at 13:00.
100 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.