×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    3

    saving a SVG image in j2me

    HI,
    I am drawing on canvas using SVG libraries, free hand drawing.After drawing on canvas,want to save drawn image in memory.So how to save SvgImage object reference.

    public void paint(Graphics g) {
    // *** clear the display
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, getWidth(), getHeight());
    // *** render the SVG image
    sg.bindTarget(g);// sg stands for Scalable Graphics
    sg.setTransparency(1f);
    sg.render(0, 0, svgImage);
    sg.releaseTarget();
    }

    after free hand drawing on this canvas, i want to save updated image in memory.
    Plz Help me.......

  2. #2
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: saving a SVG image in j2me

    Hi javavikas and Welcome to Nokia Discussion Boards,

    did you try canvas screenShot explained here? . After capturing the screen, use PNG encoding to save as an image file to your file system.

    And also use Nokia UI APIs DirectUtils.createImage(width,height,0) for creating image while taking screen shot. Directutils.creatImage returns mutable image.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    3

    Re: saving a SVG image in j2me

    Thanks Bandarap..
    One thing i would like to ask, I am drawing on svg image on user input on touch screen, line between two consecutive coordinates etc. I m facing one problem that sometimes line draw automatically at nrandom location.Below is source code .What could be the problem.It gives Random lines when we drag pointer very slowly.On C3-01 response is very bad.And on Asha Series 303 also coming.But line should be draw as per pointer event. I m very upset.Plz Help Me.
    public class SvgCanvas extends Canvas{
    boolean flag = false;
    int _lastX = 50;
    int _lastY = 50;
    Image backImage = null;
    private static final String SVG_NAMESPACE_URI = "http://www.w3.org/2000/svg";
    private static String XLINK_NAMESPACE_URI = "http://www.w3.org/1999/xlink";
    private boolean menuOnFlag = false;
    Image finalDrawnIage = null;
    Graphics graphics = null;
    static int count=1;
    Vector elements=null;
    SVGSVGElement sVGSVGElement=null;
    /**
    * Constructor.
    */
    public SvgCanvas(boolean suppressKeyEvents, String ImagePath) {

    setFullScreenMode(true);
    elements=new Vector();
    // *** setup an instance of ScalableGraphics
    sg = ScalableGraphics.createInstance();
    sg.setRenderingQuality(sg.RENDERING_QUALITY_HIGH);

    // *** create a simple SVG image

    // ** create an empty image
    //svgImage = (SVGImage)( SVGImage.createEmptyImage( null ) );

    try {
    // InputStream svgStream = getClass().getResourceAsStream(ImagePath);
    svgImage = (SVGImage) (SVGImage.createEmptyImage(null));

    // ** set the width and height of the document to match the screen capabilities
    // svgImage.setViewportWidth( getWidth() );
    // svgImage.setViewportHeight( getHeight() );

    } catch (Exception e) {
    e.printStackTrace();
    }
    svgImage.setViewportHeight(320);
    svgImage.setViewportWidth(240);
    // ** grab the root <svg> element
    sVGSVGElement = (SVGSVGElement) (svgImage.getDocument().getDocumentElement());




    }

    /**
    * Paint method.
    */
    public void paint(Graphics g) {

    sg.bindTarget(g);
    sg.setTransparency(1f);
    sg.render(0, 0, svgImage);

    sg.releaseTarget();

    }
    /*
    * Private members
    */
    private ScalableGraphics sg = ScalableGraphics.createInstance();;
    private SVGImage svgImage;







    public void drawLine(int x, int y) {

    // rootElement = SingletonClass.getSVGSVGInstance(svgImage);
    System.out.println("line b/w :"+"("+_lastX+","+_lastY+")"+"and"+"("+x+","+y+")");
    Document _document = svgImage.getDocument();
    SVGElement newElement = (SVGElement) _document.createElementNS("http://www.w3.org/2000/svg", "line");
    newElement.setFloatTrait("x1", _lastX);
    newElement.setFloatTrait("y1", _lastY);
    newElement.setFloatTrait("x2", x);
    newElement.setFloatTrait("y2", y);
    newElement.setTrait("stroke", "red");
    newElement.setFloatTrait("stroke-width", 4);
    sVGSVGElement.appendChild(newElement);
    repaint();
    }

    protected void pointerDragged(int i, int i1) {
    super.pointerDragged(i, i1);
    System.out.println("pointerDragged :"+"("+i+","+i1+")");
    drawLine(i, i1);
    _lastX=i;
    _lastY=i1;
    }

    protected void pointerPressed(int i, int i1) {
    super.pointerPressed(i, i1);
    System.out.println("pointerPressed :"+"("+i+","+i1+")");
    _lastX=i;
    _lastY=i1;
    }

    protected void pointerReleased(int i, int i1) {
    super.pointerReleased(i, i1);
    System.out.println("pointerReleased :"+"("+i+","+i1+")");
    drawLine(i, i1);
    _lastX=i;
    _lastY=i1;
    }

    public void paiting(Graphics g)
    {Image image=null;
    try {
    image=Image.createImage("/bg_1.jpg");

    } catch (IOException ex) {
    ex.printStackTrace();
    }

    }

    }

  4. #4
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: saving a SVG image in j2me

    Hi Javavikas,

    Tested your code on C3-01 and Asha 303. It works fine couldn't see any random drawing, but I noticed that drawing on Asha 303 is bit smoother.

    My device C3-01 having firmware version RM-640. Check your device c3-01 firmware version that might help.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    3

    Re: saving a SVG image in j2me

    I am very kind of you for considering my queries.Thanks a lot, yes you are right.On c3-01 sometimes appears random patterns,and on Asha 303 its smooth.
    ---------------------------------------------------------------------------------------------
    One more issue with this drawing--When user drawn on screen, for every pixel drawing i am creating an SVGElement objects(in drawCircle() and in drawLine() method),when user continue drawing 25 minutes around ,after that it crashes.There is any other to avoid these object creation and releasing memory.I have used system.gc(); after every 25 SVGElement object creation i m calling System.gc(). still is is crashing.
    Please suggest the possible ways to get rid off this memory problem.

  6. #6
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: saving a SVG image in j2me

    after drawing with SVGElement objects, you can set object to null so that garbage collector reclaims the memory immediately.

Similar Threads

  1. Saving an image
    By chandran.biju007 in forum Mobile Java General
    Replies: 6
    Last Post: 2011-01-12, 18:54
  2. image saving on N900
    By mind_freak in forum Nokia N9
    Replies: 8
    Last Post: 2010-12-22, 06:59
  3. Saving Image
    By snehalpatil in forum Mobile Java General
    Replies: 5
    Last Post: 2010-07-27, 06:19
  4. saving image from URL
    By _nomad_ in forum Symbian
    Replies: 2
    Last Post: 2005-04-20, 06:51
  5. saving an image
    By gaurav17281 in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-06-16, 05:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×