Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to draw controls on bitmap

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): Symbian
S60 5th Edition
Article
Keywords: CWindowToBitmapMappingGc CCoeControl CFbsBitmap SetCustomGc CWsScreenDevice CFbsBitmapDevice CFbsBitGc
Created: chenziteng (08 Nov 2009)
Last edited: hamishwillee (24 Jun 2011)

Contents

Overview

By default a control will draw itself on the screen by the system default Gc, but in some cases developers need it to draw itself on a bitmap, for example when implementing transition effect of view switching both views' screen shots are needed. The article shows how to force some controls (derived directly or indirectly from CCoeControl) to draw them self on a specified bitmap instead of screen.

Solution

The CCoeControl::SetGc() or CCoeControl::SetCustomGc() can be used to redirect the control's drawing to a custom Gc, but the functions accept a pointer to a window gc only, that means a bitmap gc can no be used directly. The CWindowToBitmapMappingGc introduced in Symbian OS v7.0 can be used to resolve the problem, because it can map all the operations on a window gc to a bitmap gc.

// .mmp
...
// begin by chen
LIBRARY egul.lib // CWindowToBitmapMappingGc
LIBRARY bitgdi.lib // CFbsBitmapDevice
LIBRARY imageconversion.lib // CImageEncoder
// end by chen
...
// .cpp
...
// begin by chen
#include <gulgcmap.h> // CWindowToBitmapMappingGc
#include <ImageConversion.h> // CImageEncoder
// end by chen
...
TBool CGoodbyeHellAppUi::HandleDummyDrawNowMenuItemSelectedL( TInt aCommand )
{
// TODO: implement selected event handler
// begin by chen
RFs& fs = iCoeEnv->FsSession();
CCoeControl* control = iGoodbyeHellContainer; // the control to be drawn
CWsScreenDevice* wsScreenDevice = iCoeEnv->ScreenDevice();
CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; // the bitmap on which the control to be drawn
CleanupStack::PushL(bitmap);
TInt err = bitmap->Create(control->Size(), wsScreenDevice->DisplayMode());
User::LeaveIfError(err);
CFbsBitmapDevice* bitDevice = CFbsBitmapDevice::NewL(bitmap);
CleanupStack::PushL(bitDevice);
CFbsBitGc* bitGc = NULL;
err = bitDevice->CreateContext(bitGc);
User::LeaveIfError(err);
CleanupStack::PushL(bitGc);
CWindowToBitmapMappingGc* w2bGc = CWindowToBitmapMappingGc::NewL(*wsScreenDevice, *bitGc);
CleanupStack::PushL(w2bGc);
control->SetCustomGc(w2bGc); // set GC to the one we created
control->DrawNow(); // then draw the control (now on the bitmap we created)
control->SetCustomGc(NULL); // reset the GC
 
// in this example we'd like to save the bitmap to a .bmp file
// so that we can easily check it out
_LIT(KFileName, "c:\\data\\control.bmp");
_LIT8(KMIME, "image/bmp");
CImageEncoder* encoder = CImageEncoder::FileNewL(fs, KFileName, KMIME, CImageEncoder::EOptionAlwaysThread);
CleanupStack::PushL(encoder);
TRequestStatus status = KRequestPending;
encoder->Convert(&status, *bitmap);
User::WaitForRequest(status);
User::LeaveIfError(status.Int());
CleanupStack::PopAndDestroy(encoder);
 
CleanupStack::PopAndDestroy(w2bGc);
CleanupStack::PopAndDestroy(bitGc);
CleanupStack::PopAndDestroy(bitDevice);
CleanupStack::PopAndDestroy(bitmap);
// end by chen
return ETrue;
}
...

More details about how to draw controls on bitmap please refer to the full example.

Note: to draw a listbox on bitmap please refer to the forum discussion

Source Code

Full example: File:GoodbyeHell(DrawControlsOnBitmap).zip

Screenshot

DrawControlsOnBitmap.PNG

The bitmap (the wiki doesn't accept .bmp file so I had to convert it to a .png file):

DrawControlsOnBitmap(control.bmp).PNG

This page was last modified on 24 June 2011, at 09:15.
43 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×