×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: Screenshot

  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Screenshot

    Is there a way to read the canvas as an image? Yes, I am talking about taking a screenshot of the canvas, is it possible?

    Thanks

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

    Thumbs up Re: Screenshot

    Quote Originally Posted by mohitrb1 View Post
    Is there a way to read the canvas as an image? Yes, I am talking about taking a screenshot of the canvas, is it possible?

    Thanks
    Hello,
    are you looking for the image in the gallery after you take the screnshot,then there are the software for this, you can search this on web. you run your app and then press the particular key then screnshot will be taken and image will be in the gallery.

    if you are looking for something else then write?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    But those applications use C++ and not J2ME, hence is there any option to use J2ME, to just know what is being painted on my canvas?

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

    Re: Screenshot

    Replace:

    Code:
    protected void paint(Graphics g) {
        // your painting code here
    }
    With this:

    Code:
    private Image buffer;
    
    private void paintBuffer(Graphics g) {
        // your painting code here
    }
    
    protected void paint(Graphics g) {
        if (buffer == null) {
            buffer = Image.createImage(getWidth(), getHeight());
        }
        paintBuffer(buffer.getGraphics());
        g.drawImage(buffer, 0, 0, Graphics.TOP | Graphics.LEFT);
    }
    
    protected void sizeChanged(int width, int height) {
        // force creation of new buffer
        buffer = null;
    }
    Then, you have an Image object with whatever you painted. This will contain only the "body" of the Canvas, not the status or softkey areas (if the Canvas is not full-screen).

    Graham.

  5. #5
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    Thanks. That's a neat trick!
    Although its not working for my case. I am playing a video (.mp4) on the canvas, and I am unable to get the required screenshot of the video frame (along with the canvas). Is it possible?

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

    Re: Screenshot

    Ah, no, I'm afraid not. You can't get the contents from the Canvas.

    Graham.

  7. #7
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    Hi Graham
    I was just going through MMAPI and came across the method: getSnapShot(), which can "Get a snapshot of the displayed content." (as the API says). Does it mean it can get a snapshot of whatever being displayed on the screen, or a snapshot using the cellphone's camera?

    Thanks

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Screenshot

    Quote Originally Posted by mohitrb1 View Post
    Hi Graham
    I was just going through MMAPI and came across the method: getSnapShot(), which can "Get a snapshot of the displayed content." (as the API says). Does it mean it can get a snapshot of whatever being displayed on the screen, or a snapshot using the cellphone's camera?

    Thanks

    getSnapShot() method is defined for VideoControl, it can only be used to capture the still snapshots from camera or still from VideoPlayer.

    thanks,
    ~Amitabh

  9. #9
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    What do you mean by
    still from VideoPlayer
    ?
    Does it allow to take a still from a pre-recorded video?

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Screenshot

    Didnt tried it but hope so, you can try it by getting a VideoControl out the player palying the recorded video and then use getSnapshot() on it.

    PHP Code:
    try {
           
    Player p Manager.createPlayer("http://abc.mpg");
           
    p.realize();
           
    VideoControl vc;
           if ((
    vc = (VideoControl)p.getControl("VideoControl")) != null)
               
    vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEOcanvas));
           
    vc.setVisible(true);
           
    p.start();
           
    // Sleep for sometime
           // use vc.getSnapShot() to capture.
       
    } catch (MediaException pe) {
       } catch (
    IOException ioe) {
       } 
    thanks,
    ~Amitabh

  11. #11
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    Hi I have been following the same approach, but I didn't understand why you asked?
    // Sleep for sometime
    I am invokig this piece of code, when user press the getSnap command button:
    byte[] raw = videoControl.getSnapshot(null);
    if (raw!=null){
    image = Image.createImage(raw, 0, raw.length);
    }
    And then I am drawing it on the cavas using g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);

    But nothing is being drawn And I checked that both raw and image are not null.

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Screenshot

    Quote Originally Posted by mohitrb1 View Post
    Hi I have been following the same approach, but I didn't understand why you asked?


    I am invokig this piece of code, when user press the getSnap command button:
    byte[] raw = videoControl.getSnapshot(null);
    if (raw!=null){
    image = Image.createImage(raw, 0, raw.length);
    }
    And then I am drawing it on the cavas using g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);

    But nothing is being drawn And I checked that both raw and image are not null.
    Check that you created this videoControl from your player object:
    PHP Code:
           if ((vc = (VideoControl)p.getControl("VideoControl")) != null
               
    vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEOcanvas)); 
           
    vc.setVisible(true); 
    And you capture when the player has already started the movi e playback.

    Try with different encodings:
    getSnapshot

    public byte[] getSnapshot(java.lang.String imageType)
    throws MediaException

    Gets a snapshot of the displayed content. Features and format of the captured image are specified by the imageType. All implementations support at least PNG format. Available formats can be queried from System.getProperty with video.snapshot.encodings as the key.
    Parameters:
    imageType - Format and resolution of the returned image. If null is given, it will default to using the PNG format.
    Returns:
    image as a byte array in required format.
    Throws:
    IllegalStateException - Thrown if initDisplayMode has not been called.
    MediaException - Thrown if the requested format is not supported.
    SecurityException - Thrown if the caller does not have the security permission to take the snapshot.

    thanks,
    ~Amitabh

  13. #13
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    I have been able to play, pause, fast forward, rewind a pre-recorded video, hence I dont think there is any error in videoControl or Player. And I have already checked before that Nokia N97 supports jpeg, jpg, png, bmp, and gif. Not even any exception is thrown, also the "image" obtained using getSnapshot (after converting from byte array) is not null. But why g.drawImage is unable to draw this image on the canvas? Do you have any example where it's shown that getSnapshot can capture a frame from a pre-recorded video which is playing on the canvas?

    Thanks

  14. #14
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Screenshot

    Try to display this image on a new form or new Canvas, I have tested this on Nokia N95 and it works.
    I used videoControl.getSnapshot("encoding=jpeg");

    thanks,
    ~Amitabh
    Last edited by im2amit; 2010-03-22 at 16:16. Reason: encodings to encoding

  15. #15
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    76

    Re: Screenshot

    Hi Amitabh
    Just to note: It should be "encoding" (with no "s" at the end).

    I have tried all the options, but still the image is not appearing. I am using N97. Could you please post your sample code somewhere, or email me {<NokiaForum_Username>@gmail.com. I am not a big fan of emailing codes, but I have been stuck with this silly problem for almost a week now :|}

    Thanks

Similar Threads

  1. Get a screenshot
    By er_benji in forum Symbian Media (Closed)
    Replies: 14
    Last Post: 2012-02-22, 12:39
  2. Problem while capturing ScreenShot
    By gaurav.gupta in forum Symbian
    Replies: 10
    Last Post: 2009-06-24, 07:51
  3. Replies: 2
    Last Post: 2009-06-09, 06:24
  4. screenshot if application is not on top
    By lkz633 in forum Symbian
    Replies: 1
    Last Post: 2007-03-16, 02:56

Posting Permissions

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