aspose file tools*
The moose likes Java Micro Edition and the fly likes Zoom In/Zoom Out Image with j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Zoom In/Zoom Out Image with j2me" Watch "Zoom In/Zoom Out Image with j2me" New topic
Author

Zoom In/Zoom Out Image with j2me

Parth Mankad
Greenhorn

Joined: Jan 27, 2003
Posts: 18
Hello everybody

i am developing a small application in which i download a .jpg image from web and display it on the mobile.that part works fine.now i want to add Zoom In/Zoom Out feature in my application.Plz can someone tell me how to do it and integrate it with my exisiting code.below is my code where in i get a image from web.

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Zoom extends MIDlet implements CommandListener
{
private Display display;
private int screenHeight;
private int screenWidth;
private int numColors;
private StringItem message;
private byte[] data;
private Image image,displayed;
private ShowImage showimage;
private TextBox entryForm;
private Command okCommand = new Command("OK", Command.OK, 1);
private Command zoomCommand=new Command("ZOOM",Command.SCREEN,2);
private Command exitCommand = new Command("EXIT", Command.EXIT, 2);

public Zoom()
{
}

protected void startApp() throws MIDletStateChangeException
{
initMIDlet();
HttpConnection conn = null;
try
{
conn =(HttpConnection)Connector.open("url");
int rc = conn.getResponseCode();
if (rc == HttpConnection.HTTP_OK)
{
try
{
DataInputStream din =new DataInputStream(conn.openInputStream());
data = new byte[(int)conn.getLength()];
din.readFully(data);
din.close();
}
catch (IOException e)
{
}
new
}
else
{

}
conn.close();
}
catch (IOException e)
{

}

}
public void exitMIDlet(){
notifyDestroyed();
}
private void initMIDlet()
{
display = Display.getDisplay(this);
entryForm = new EntryForm();
display.setCurrent(new DummyCanvas());

}

public void commandAction(Command c, Displayable d)
{
if (c == okCommand)
{
display.setCurrent(showimage);
}

else
{
exitMIDlet();
}
}

class DummyCanvas extends Canvas
{
protected void paint(Graphics g)
{
screenHeight = getHeight();
screenWidth = getWidth();
numColors = display.numColors();

// Go directly to the main screen

display.setCurrent(entryForm);
}
}
class EntryForm extends TextBox
{
EntryForm()
{
super("Enter a URL", "image",20, 0);
addCommand(exitCommand);
//addCommand(sendCommand);
setCommandListener(Zoom.this);
}
}


// Show the image...

class ShowImage extends Canvas
{

ShowImage(byte[] imageData )
{
image = Image.createImage( imageData,0,imageData.length );
display.setCurrent( this );
addCommand(okCommand);
addCommand(zoomCommand);
addCommand(exitCommand);
setCommandListener( Zoom.this );
}

protected void paint( Graphics g )
{
g.drawImage(image, 0, 5,g.TOP | g.LEFT );
}


}
protected void pauseApp(){
}

protected void destroyApp( boolean
unconditional )
throws MIDletStateChangeException {
exitMIDlet();
}


}

thanx
parth
payal agrawal
Ranch Hand

Joined: Oct 11, 2005
Posts: 44
Look at the URL below:

How to implement Zoom in and Zoom out
http://www.java-tips.org/content/view/544/73/

You can add the code after you create Image from HTTP download.
Parth Mankad
Greenhorn

Joined: Jan 27, 2003
Posts: 18
hello payal

i tried to use the code from the link given by u.but i am getting java.lang.outofmemory exception.plz help

parth
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
I am getting error on this line : variable Connector

conn =(HttpConnection)Connector.open("url");

Am I missing anything to be imported or any of the jar files not there in the classpath?

Rgds,

Seetesh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Zoom In/Zoom Out Image with j2me