Downscaling images by dimension

The following code example shows how to downscale images by dimension.

package com.nokia.evo.java.test.imagescale;

import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.nokia.mid.imagescale.ImageScaler;
import com.nokia.mid.imagescale.ImageScalerException;
import com.nokia.mid.imagescale.ImageScalerListener;

public class ImageScalingResolutionExample extends MIDlet implements ImageScalerListener{
	
	private String srcFile = "file:///MemoryCard/big.jpg";
	private String destFile = "file:///MemoryCard/small.jpg";
	private int jpegQuality = 0;
	private int xReso = 640;
	private int yReso = 640;
	private boolean keepRatio = true;
	Form form = new Form("ImageScaling Example");
	
	public ImageScalingResolutionExample() {
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

	}

	protected void pauseApp() {

	}

	protected void startApp() throws MIDletStateChangeException {
		Display.getDisplay(this).setCurrent(form);
		ImageScaler is = new ImageScaler(srcFile, destFile);
		is.addListener(this);
		if (jpegQuality != 0)
		{
			is.setJpegQuality(jpegQuality);
		}				
		int result = -1;
		try {
			result = is.scaleImage(xReso, yReso, keepRatio);
		} catch (ImageScalerException e) {
		}
		if (result <= 0){
			Ticker ticker = new Ticker("Scale image " + srcFile + " fail!");
			form.setTicker(ticker);
		}
		

	}
	
	public void scaleFinished(int requestId, int result){
		if (result == 0){
			Ticker ticker = new Ticker("[" + requestId + "]: Scale OK!");
			form.setTicker(ticker);
			
		}else{
			Ticker ticker = new Ticker("[" + requestId + "]: Scale Fail! result=[" + result + "]");
			form.setTicker(ticker);
		}
			
	}

}