salve a tutti, spero che qualcuno riesca a darmi una mano su questo problema che non riesco a risolvere da 3 giorni...!
devo riuscire a far visualizzare un'immagine all'interno di un canvas, ho fatto delle prove e a quanto pare l'immagine la carica all'interno del try/catch, ma mi manda in errore quando la vado a stampare con il g.drawImage()...!
ecco il codice! (uso il wtk 2.5.2, l'immagine è dentro la cartella res del progetto!!)
Codice PHP:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class ProvaGrafica1 extends MIDlet implements CommandListener
{
Command exitCommand;
Form form;
public ProvaGrafica1() { }
private Image image;
private final static String IMAGE_PATH = "/baby1.png";
public void setFullScreenMode(boolean mode) { }
public void startApp()
{
exitCommand = new Command("exit",Command.EXIT,0);
image = null;
try
{ image = Image.createImage(IMAGE_PATH);
System.out.println("immagine caricata");}
catch(IOException ioe)
{
System.out.println("errore nel caricare l'immagine");
Alert errorAlert = new Alert("Errore","Image not present",null,AlertType.ERROR);
errorAlert.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(errorAlert);
}
Canvas1 movableCanvas = new Canvas1();
movableCanvas.setFullScreenMode(true);
Display.getDisplay(this).setCurrent(movableCanvas);
}
public Form getForm()
{
if (form == null)
{
form = new Form("Welcome", new Item[] {});
form.setCommandListener(this);
}
return form;
}
public void commandAction(Command c, Displayable d)
{
if (c==exitCommand && d==getForm()){Display.getDisplay(this).setCurrent(getForm());}
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
class Canvas1 extends Canvas{
private final static int RAGGIO = 20;
private final static int STEP = 5;
private int x,y;
public void paint(Graphics g){
// Determiniamo le dimensioni del Canvas
int canvasWidth = getWidth();
int canvasHeight = getHeight();
g.setColor(0x0000ff);
g.fillRect(0,0,canvasWidth,canvasHeight);
g.setColor(0xff0000);
g.fillArc(x-RAGGIO,y-RAGGIO,RAGGIO*2,RAGGIO*2,0,360);
if (image== null) System.out.println("immagine inesistente");
g.drawImage(image, 50/*302(360-(360/20)-40)*/, 50/*58(20+40)*/, Graphics.BASELINE | Graphics.LEFT);
}// fine
protected void pointerPressed(int x, int y){
move(x, y);
}// fine
public void move(int moveX, int moveY)
{
x=moveX;
y=moveY;
if ((x >= (360-(360/20)-40)) && (x <= (360-(360/20))) && (y >= 20) && (y <= 60)) commandAction(exitCommand, getForm());
repaint();
serviceRepaints();
}
}
public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}
}
l'immagine è più piccola del canvas!!
spero qualcuno riesca a darmi una mano!!!

Rispondi quotando