• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Zoom In/Zoom Out Image with j2me

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic