J'ai lu ici qu'il était possible de dessiner dans une image, comme dans un canvas.
J'ai réalisé un petit script qui permet l'importation d'un SVG dans un canvas :
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.*;
import javax.microedition.midlet.*;
public class SVGToCanvas extends MIDlet implements CommandListener{
private final Command start=new Command("Start",Command.OK,2);
private final Command exit=new Command("Exit",Command.EXIT,1);
private SVGCanvas canvas;
public SVGToCanvas(){
}
public void startApp(){
try{
canvas=new SVGCanvas((SVGImage)SVGImage.createImage((InputStream)getClass().getResourceAsStream("/logo.svg"),null));
canvas.addCommand(start);
canvas.addCommand(exit);
canvas.setCommandListener(this);
}
catch(IOException e){
e.printStackTrace();
}
Display.getDisplay(this).setCurrent(canvas);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c,Displayable d){
if (c==exit){
destroyApp(false);
notifyDestroyed();
}
}
}
class SVGCanvas extends Canvas{
protected SVGImage svgImage;
protected ScalableGraphics sg=ScalableGraphics.createInstance();
protected SVGCanvas(final SVGImage svgImage){
this.svgImage=svgImage;
}
public void paint(Graphics g){
g.setColor(219,238,255);
g.fillRect(0,0,getWidth(),getHeight());
sg.bindTarget(g);
svgImage.setViewportWidth(getWidth());
svgImage.setViewportHeight(getHeight());
sg.render(0,0,svgImage);
sg.releaseTarget();
}
}
Partant de ce script d'importation d'une image :
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageItemMIDlet extends MIDlet{
public ImageItemMIDlet(){
}
Display display=Display.getDisplay(this);
public void startApp()
{
Form form = new Form("Form example");
try{
Image Logo =Image.createImage("/logo.png");
//ImageItem(label,Image,layout,alternative text)
ImageItem imageitem =new ImageItem("ImageItem Example",Logo,ImageItem.LAYOUT_CENTER,"");
form.append(imageitem);
}
catch(IOException ex){
System.out.println("Exception occurred: "+ex);
}
display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
}
Comment puis-je lier les deux, svp? à savoir, dessiner mon SVG dans une image, pour l'ajouter à mon formulaire...
Faire un formulaire SVG
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.