×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    97

    Question capture screen image through background exe

    how to capture screen image through background exe.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: capture screen image through background exe

    just the same as you would do it in a GUI app, except that you would need to construct the screen device yourself..

  3. #3
    Registered User
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    1,503

    Re: capture screen image through background exe

    Quote Originally Posted by cool_ranjeet View Post
    how to capture screen image through background exe.
    Use the following code

    Code:
        RWsSession ws;
        User::LeaveIfError(ws.Connect());
        CleanupClosePushL(ws);
        CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
        CleanupStack::PushL(screen);
        screen->Construct();
    
        CFbsBitmap *aBitmap;
        aBitmap = new(ELeave) CFbsBitmap();
        aBitmap->Create(screen->SizeInPixels(), screen->DisplayMode());
        screen->CopyScreenToBitmap(aBitmap);
        
    
        RWindowGroup wg(ws);
        User::LeaveIfError(wg.Construct(reinterpret_cast<TUint32>(&wg), EFalse));
        CleanupClosePushL(wg);
        wg.SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront);
        TRequestStatus status,aLightStatus;                      
        CWindowGc* gc;
        User::LeaveIfError(screen->CreateContext(gc));
        CleanupStack::PushL(gc);
       	RWindow window(ws);
        User::LeaveIfError(window.Construct(wg, reinterpret_cast<TUint32>(&wg) + 1));
        CleanupClosePushL(window);
        window.SetBackgroundColor(TRgb(0x90, 0x90, 0x90));
        window.Activate();
        // window.SetExtent(TPoint(0,0), TSize(screenWidth, screenHeight));
        window.SetExtent(TPoint(0,0), screen->SizeInPixels());
        window.SetVisible(ETrue);
        gc->Activate(window);
        
        TRect rect = TRect(window.Size());
        window.Invalidate(rect);
        window.BeginRedraw(rect);
        gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
        aBitmap->Save(TBitMapFile);
        gc->Clear();
        gc->DrawBitmap(rect,aBitmap);
    Regards,
    Amit


    ****"Putting a Smile on other's faces is the essence of true Happiness"****

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Re: capture screen image through background exe

    How do you declare the variable TBitMapFile with the path in the above example?

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: capture screen image through background exe

    What would you need to do with the TBitMapFile ?

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: capture screen image through background exe

    TBitMapFile has a bad name, otherwise it is just a normal filename.
    Code:
    _LIT(KFileName,"c:\\data\\test.mbm");
    Note that CFbsBitmap::Save saves files in Symbian's own .mbm file format.
    CImgageEncoder is the class you can use for encoding into well-known formats (like .bmp or .jpg), you can find usage examples in the Wiki.
    Note that the CopyScreenToBitmap line does the screen capture, the rest of the code is not important (except for the actual saving of course).
    Also note that if you need this code in a GUI-less executable, you will need an RFbsSession. Just instantiate and Connect somewhere at the beginning, and Disconnect/Close at the end.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Re: capture screen image through background exe

    TSize screenSize = CEikonEnv::Static()->ScreenDevice()->SizeInPixels();//gets size of screen
    //TSize stores 2 dimensional size(height,widht)
    //Every GUI application is provided with an instance of CEikonEnv by the framework, which can be accessed through CEikonEnv::Static()

    TDisplayMode displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();
    CFbsBitmap*iBitmap = new (ELeave) CFbsBitmap();
    User::LeaveIfError(iBitmap->Create(screenSize, displayMode));
    TInt err = CEikonEnv::Static()->ScreenDevice()->CopyScreenToBitmap(iBitmap);
    iBitmap->Save(_L("c:\\system\\apps\\screen.mbm")); // here u can say
    TFileName filename;
    filename.Copy(_L("c:\\system\\apps\\1.jpg"));

    CImageEncoder* iencoder = CImageEncoder::FileNewL(
    CEikonEnv::Static()->FsSession(),
    filename,_L8("image/jpeg"),
    CImageEncoder::EOptionAlwaysThread);

    CleanupStack::PushL(iencoder);
    TRequestStatus aStatus = KErrNone;
    iencoder->Convert( &aStatus, *iBitmap );
    User::WaitForRequest( aStatus );
    CleanupStack::PopAndDestroy(); // captured image as MBM
    return 0;

    This is the code i am running as a c open console project and running on s60v3fp2 emulator.But neither the .mbm file is created nor the .jpg file.
    Thanks.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: capture screen image through background exe

    a) since it is an Open C console project, the "every GUI application..." thing does not apply to it, CEikonEnv::Static will return a NULL pointer, and your application ends with KERN-EXEC 3 panic
    b) enable the error messages in order to see them (like the KERN-EXEC 3): http://www.developer.nokia.com/Commu...ded_panic_code
    c) since it is an Open C console project, my remark about RFbsSession also applies, I do not see it in the code
    So you have to create the CWsScreenDevice object manually
    Code:
    RWsSession ws;
    User::LeaveIfError(ws.Connect());
    CleanupClosePushL(ws);
    CWsScreenDevice *wsd=new(ELeave)CWsScreenDevice;
    CleanupStack::PushL(wsd);
    User::LeaveIfError(wsd->Construct());
    User::LeaveIfError(RFbsSession::Connect());
    then you can use wsd instead of CEikonEnv::Static()->ScreenDevice().

  9. #9
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Re: capture screen image through background exe

    Now how do i compress the .mbm file to .jpg?

  10. #10
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: capture screen image through background exe

    here's wiki article for image encoder API usage: http://www.developer.nokia.com/Commu..._image_to_JPEG

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: capture screen image through background exe

    The CImageEncoder part seems to be fine in your code snippet anyway, just execution simply did not reach that point.

  12. #12
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Re: capture screen image through background exe

    RWsSession ws;
    User::LeaveIfError(ws.Connect());
    CleanupClosePushL(ws);
    CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
    CleanupStack::PushL(screen);
    screen->Construct();

    CFbsBitmap *aBitmap;
    aBitmap = new(ELeave) CFbsBitmap();
    aBitmap->Create(screen->SizeInPixels(), screen->DisplayMode());
    screen->CopyScreenToBitmap(aBitmap);



    _LIT(KFileName,"c:\\test.mbm");
    aBitmap->Save(KFileName);


    TFileName filename;
    filename.Copy(_L("c:\\system\\Apps\\1.jpg"));

    CImageEncoder* iencoder = CImageEncoder::FileNewL(
    CEikonEnv::Static()->FsSession(),
    filename,_L8("image/jpeg"),
    CImageEncoder::EOptionAlwaysThread);

    CleanupStack::PushL(iencoder);
    TRequestStatus aStatus = KErrNone;
    iencoder->Convert( &aStatus, *aBitmap );
    User::WaitForRequest( aStatus );

    CleanupStack::PopAndDestroy();



    RFbsSession:isconnect();

    return 0;

    Only .mbm file is getting created,no jpg file.
    Thanks.

  13. #13
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: capture screen image through background exe

    you should not use WaitForRequest, it would be better to use real Active objects. Anyway, so check what error is given with aStatus, could be that you for example forgot to make sure that the fodler exists, or could be some other problem, anyway the error code would propably tell the excat one.,

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    34

    Re: capture screen image through background exe

    "CImageEncoder* iencoder = CImageEncoder::FileNewL(
    CEikonEnv::Static()->FsSession(),
    filename,_L8("image/jpeg"),
    CImageEncoder::EOptionAlwaysThread);"
    the code is not executing from this line.If i display something befor ethis line,it executes,but nothing after that executes.
    Some problem in this line.
    Thanks.

  15. #15
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: capture screen image through background exe

    it likely crashes with Kern-Exec 3, basically with applications not implementing application framework, you would not have CEikonEnv::Static(), so instead of using it, you should use your own Rfs instance. Also in future please check panic codes for crashes: http://www.developer.nokia.com/Commu...ded_panic_code

Similar Threads

  1. Can't capture keypress in background application
    By Jick in forum Symbian User Interface
    Replies: 4
    Last Post: 2010-04-07, 05:39
  2. J2me polish background image problem
    By poojs in forum Mobile Java General
    Replies: 5
    Last Post: 2009-05-29, 11:06
  3. J2me polish background image problem
    By poojs in forum Feedback - Nokia Developer Services & Infrastructure
    Replies: 1
    Last Post: 2009-05-25, 07:08
  4. Replies: 2
    Last Post: 2008-01-15, 11:53
  5. how can i capture image with a background image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2007-01-23, 16:35

Posting Permissions

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