×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Lightbulb J2ME Screenshot of a Canvas

    Hi,

    I'm currently trying to


    My objective : I want that the user make a signature on touchscreen (using stylet), and then send it to a server.

    I saw a method getScreenShot(), that seems to do what i first want, but can't figure how it works (about 2line...) and how to use it...
    Code:
        public Image getScreenShot() {
            Image screenshot = Image.createImage(getWidth(), getHeight());
            Graphics g = screenshot.getGraphics();
            paint(g);
            return Image.createImage(screenshot);
        }
    Has anyone did this ?

    Thanks in advance

  2. #2
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Lightbulb Re: J2ME Screenshot of a Canvas

    I think there is no direct way of taking screenshot of canvas in J2ME..

    You can see the below two discussions..

    http://discussion.forum.nokia.com/fo...2me+screenshot

    http://discussion.forum.nokia.com/fo...2me+screenshot

    Best regards,

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Re: J2ME Screenshot of a Canvas

    Thanks for your response

    I've already read those.

    The guy says :
    You can however take a "screenshot" of the Canvas, if you're using one: http://discussion.forum.nokia.com/fo...ght=screenshot
    But i've never achieved this...

    I really think that this is possible, but don't have time to make more inquiry, and hope someone has already done this...

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME Screenshot of a Canvas

    Quote Originally Posted by mtgbe View Post
    I saw a method getScreenShot(), that seems to do what i first want, but can't figure how it works (about 2line...) and how to use it...
    Code:
        public Image getScreenShot() {
            Image screenshot = Image.createImage(getWidth(), getHeight());
            Graphics g = screenshot.getGraphics();
            paint(g);
            return Image.createImage(screenshot);
        }
    Assuming your Canvas's paint() method works correctly, this should return an Image identical to the screen contents. Are you saying it doesn't? It returns an Image object, not a PNG encoded image.

    You'll need to use Image.getRGB() to get the pixel data in an int[]. That int[] then needs to be split into four byte[]s to make it compatible with the PNG encoder. However, you could simply store the int[] (along with the width and height), and not bother encoding as a PNG. You don't appear to need the data in PNG format.

    Graham.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Re: J2ME Screenshot of a Canvas

    I thought about PNG for compression. Because when this will be sent to the server, what kind of image will i get there ? BMP ?

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME Screenshot of a Canvas

    Ah yes, if you're sending to a server, you will need to encode it as some format. Note, however, that the PNG encoder code you have does not compress the image. It only encodes it. It will not make the data smaller.

    You can create the four byte arrays like:

    Code:
    // get pixel data
    int width = img.getWidth();
    int height = img.getHeight();
    int[] pixels = new int[width * height];
    img.getRGB(pixels, 0, width, 0, 0, width, height);
    
    // separate channels
    byte[] red   = new byte[pixels.length];
    byte[] green = new byte[pixels.length];
    byte[] blue  = new byte[pixels.length];
    byte[] alpha = new byte[pixels.length];
    
    for (int i = 0; i < pixels.length; i++) {
        int argb = pixels[i];
        alpha[i] = (byte) (argb >> 24);
        red[i]   = (byte) (argb >> 16);
        green[i] = (byte) (argb >>  8);
        blue[i]  = (byte) (argb);
    }
    Graham.

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Re: J2ME Screenshot of a Canvas

    Ok, thanks a lot, i'll give it a try next week and will post my experience.

    If my screen is 320x240, that will make a 76.800 int array. Won't it be too much for a as small device ?

    Integer is 16 bits no ? I see that the shifts reveals 32bits... ?

    Have you heard about a good image compressor (and also not too hungry in ressources) ?

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME Screenshot of a Canvas

    Quote Originally Posted by mtgbe View Post
    If my screen is 320x240, that will make a 76.800 int array. Won't it be too much for a as small device ?
    Yes, it might be.

    Quote Originally Posted by mtgbe View Post
    Integer is 16 bits no ? I see that the shifts reveals 32bits... ?
    A Java int is 32 bits. So, the int[] will consume about 300k. The four byte arrays will need the same again. The PNG image data will also be about 300k. Make sure to add:

    Code:
    pixels = null;
    after creating the byte arrays, and before encoding the PNG, or you'll need 900k of memory. Even then, the peak memory usage will be around 600k.

    Uploading it to a server by HTTP will also consume 300k, in order to buffer the POST data.

    Quote Originally Posted by mtgbe View Post
    Have you heard about a good image compressor (and also not too hungry in ressources) ?
    No, I haven't seen a complete image encoder that includes compression. You'd need to write one.

    Assuming the image data you want to store is just two-colour (a signature drawn on a touch screen), then this PNG encoder is very inefficient. It uses 32 bits per pixel, but you need only one bit. You could fit the PNG in around 10k if you encode it differently (without compression). However, you'd need to re-write the PNG encoder.

    Graham.

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Re: J2ME Screenshot of a Canvas

    allright, i see.

    Thanks a lot for all ur explanations

    I'll give it a try and post my feedback

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Re: J2ME Screenshot of a Canvas

    Ok, I've found some interresting code to generate a monochrome bitmap inside zxing (barcode reader).

    I'll keep in touch.

Similar Threads

  1. J2ME canvas
    By HasithaRandika in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2009-01-27, 08:11
  2. How to create a partly transparent Canvas to lay on top of another Canvas?
    By mkleijer in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2007-05-22, 07:00
  3. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32
  4. Undocumented Canvas repaint/paint deadlock in Nokia j2me
    By fieres in forum Mobile Java General
    Replies: 3
    Last Post: 2005-05-31, 03:09
  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
  •