×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    3

    Save canvas image

    Hello I need some help. How do I save images have been written (touch screen) to the screen with the stylus. I came across information regarding the canvas and using FileConnection API. I am yet to be able to put everything together however. Can someone please show me how to save the written image to the memory card.

    Thanks,
    CHris

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Save canvas image

    maybe u can link to the mentioned information/articles so that someone can fill in the missing gaps ?

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Save canvas image

    Quote Originally Posted by chrismoto View Post
    Hello I need some help. How do I save images have been written (touch screen) to the screen with the stylus. I came across information regarding the canvas and using FileConnection API. I am yet to be able to put everything together however. Can someone please show me how to save the written image to the memory card.

    Thanks,
    CHris
    Hey,
    Please forgive me if I understand your post wrongly.
    Are you talking about like saving the signature kind of thing?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Regular Contributor
    Join Date
    May 2008
    Location
    Copenhagen, Denmark
    Posts
    84

    Post Re: Save canvas image

    Hi Chris, I just use RAW format for my screenshot routine - it's crude but it works:

    Code:
        public static void saveScreenDump(Image screenDump) {
            FileConnection conn = null;
            DataOutputStream dos = null;
            try {
                int[] screenDumpRGB = new int[screenDump.getWidth() * screenDump.getHeight()];
                screenDump.getRGB(screenDumpRGB, 0, screenDump.getWidth(), 0, 0, screenDump.getWidth(), screenDump.getHeight());
    
                String filename = "" + System.currentTimeMillis() + ".raw";
                String fileconn_dir = System.getProperty("fileconn.dir.photos");
                if (fileconn_dir == null || "".equals(fileconn_dir))
                    fileconn_dir = "file:///c:/other/";     // Works K600i and P990i (extremely slow!)
    
                conn = (FileConnection) Connector.open(fileconn_dir + filename, Connector.READ_WRITE);
    
                if (!conn.exists())
                    conn.create();
                dos = conn.openDataOutputStream();
                for(int i = 0; i < screenDumpRGB.length; i++)
                    dos.writeInt(screenDumpRGB[i]);
    
                System.out.println("image saved");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (dos != null)
                        dos.close();
                    if (conn != null)
                        conn.close();
                } catch (IOException e) {
                    // Well ...
                }
            }
        }
    I just did a quick search for a Java ME implementation of a PNG or JPEG encoder, but couldn't find one. But I remember this encoding has to be done manually - there's no function in JSR-135 MMAPI that encodes an Image for you.

    Also this doesn't work on Motorola phones unless you have one of their developer certificates. No access to JSR-75 FileConnection API without a certificate.

    Anyway the file is [width * height * 4] bytes.

    To convert a RAW image to PNG in Java SE:

    Code:
        if (rawFile.length() == 240 * 320 * 4) {
            int[] imageData = new int[240 * 320];
            for (int i = 0; i < imageData.length; i++)
                imageData[i] = dis.readInt();
    
            BufferedImage image = new BufferedImage(240, 320, BufferedImage.TYPE_INT_ARGB);
            image.setRGB(0, 0, 240, 320, imageData, 0, 240);
            ImageIO.write(image, "PNG", new File(rawFile.getAbsolutePath().replace(".raw", ".png")));
        }

Similar Threads

  1. Draw and save image
    By shyam9 in forum Symbian C++
    Replies: 10
    Last Post: 2008-04-08, 11:31
  2. --- ???save image problem??? ---
    By ferenn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2007-10-01, 14:33
  3. scrolling an image larger than the canvas size problem
    By noobprogrammer in forum Mobile Java General
    Replies: 4
    Last Post: 2006-11-20, 03:20
  4. how to save image taken by camera with bitmap
    By winsys in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-10-10, 05:46
  5. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46

Posting Permissions

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