×
Namespaces

Variants
Actions
Revision as of 21:58, 16 December 2013 by jsivaguru (Talk | contribs)

How to create a magnifying lens application in Asha platform

From Nokia Developer Wiki
Jump to: navigation, search

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

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


Article Metadata
Code Example
Source file: File:Magnify.zip
CompatibilityArticle
Created: jsivaguru (15 Dec 2013)
Last edited: jsivaguru (16 Dec 2013)

Introduction

The Asha platform contains several new features and APIs.Among them are the excellent image processing capabilities.We will use those feature to make a magnifying glass application.

Magnify Application

Coding

It is not possible to have a live view from the camera which is magnified.This is a limitation in the platform itself.Hence as an alternative, we will capture an image and then apply cropping and scaling techniques to get the magnified look.

The core of the magnification is in this code :

System.out.println("ABS X :" + this.getAbsoluteX() + "ABS Y:" + this.getAbsoluteY());
System.out.println("x => Pad : " + this.getStyle().getPadding(Component.LEFT) + " Margin " + this.getStyle().getMargin(Component.LEFT));
System.out.println("y => Pad : " + this.getStyle().getPadding(Component.TOP) + " Margin " + this.getStyle().getMargin(Component.TOP));
// System.out.println("A X :" + this.getX() + "A Y:" + this.getY());
 
int sub_value_x = this.getAbsoluteX() + this.getStyle().getPadding(Component.LEFT);
int sub_value_y = this.getAbsoluteY() + this.getStyle().getPadding(Component.TOP);
 
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;
 
transformControl.setSourceRect(sourceX, sourceY, breadth_rect, length_rect);
transformControl.setTargetSize(targetWidth, targetHeight, 0);
 
try
{
//javax.microedition.lcdui.Image img = javax.microedition.lcdui.Image.createRGBImage(arg0, y, y, focusScrolling)
mp.setInput(m.getFinal_image());
} catch (MediaException ex)
{
ex.printStackTrace();
}
 
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mp.setOutput(bos);
transformControl.setEnabled(true);
try
{
mp.complete();
} catch (MediaException ex)
{
ex.printStackTrace();
}
byte[] b = bos.toByteArray();
 
if (zoomfactor > 1)
{
System.out.println("ZOOMING");
//ByteArrayInputStream bis = new ByteArrayInputStream(b);
try
{
mp.setInput(javax.microedition.lcdui.Image.createImage(b, 0, b.length));
// mp.setInput(bis, b.length);
bos = new ByteArrayOutputStream();
mp.setOutput(bos);
transformControl.setSourceRect(0, 0, length_rect, breadth_rect);
 
int targetW = (int) (zoomfactor * breadth_rect);
int targetH = (int) (zoomfactor * length_rect);
transformControl.setTargetSize(targetW, targetH, 0);
transformControl.setEnabled(true);
mp.complete();
b = bos.toByteArray();
 
} catch (MediaException ex)
{
ex.printStackTrace();
}
 
}
 
scale_image = Image.createImage(b, 0, b.length);
// testFunction();
top.removeAll();
top.addComponent(new Label(scale_image));
top.repaint();
 
 
}


This is the pointer pressed method of an image added to a Form.Whenever the user clicks on a particular location on an image, we create a fixed size rectangle that we are interested in.We use the transform control in the AMMS Apis to crop the image.We now have a rectangular area surrounding the pixel we selected.

We then scale the rectangular region using the AMMS Apis to the required magnification level.

Summary

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

143 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.

×