Example of Symbian display bitmap

Source: Internet
Author: User

The key to this example is that the preparation of resource files is not very troublesome:

The placement of the image is as follows:

Create a picture folder at the same level as the group. In the folder, create a file named image1.bmp, which contains three BMP files: image1.bmp image2.bmp image2_mask.bmp.

I. Add the command to package the image file at the end of the MMP file:

Start bitmap testsvg_bmp .mbm
Header
Targetpath/resource/apps // package target location
Sourcepath ../picture/BMP // placement of the image
Source C24 image1.bmp // image name
Source C24 image2.bmp
Source 1 image2_mask.bmp
End

Ii. Define images in your xxxview. h.

Cfbsbitmap * ibackgroundimage;
Cfbsbitmap * iimage2;
Cfbsbitmap * iimage2mask;

3. Add initialization and drawing information in your xxxview. cpp file.

A: header file and definition:

# Include <aknutils. h> // SWB
# Include <graphic_bmp .mbg> // SWB bitmap Enumeration
// # Include <akniconutils. h> // definition of the akniconutils class
// # Include <graphic_svg.mbg> // bitmap Enumeration

_ Partition (ksvgpath, "// resource // apps // graphic_svg.mif ");
_ Partition (kbitmappath, "// resource // apps // graphic_bmp .mbm ");

B: constructl () initialization:

Tfilename bitmapfile (kbitmappath );
User: leaveiferror (completewithapppath (bitmapfile ));
Ibackgroundimage = ieikonenv-> createbitmapl (bitmapfile, embmgraphic_bmp image1 );
Iimage2 = ieikonenv-> createbitmapl (bitmapfile, embmgraphic_bmp image2 );
Iimage2mask = ieikonenv-> createbitmapl (bitmapfile, embmgraphic_bmp image2_mask );

C: Release in destructor:

Delete ibackgroundimage;
Delete iimage2;
Delete iimage2mask;

D: draw in the draw () function

// Implemented in the draw () function
// Draw a graph in the device drawing context class cwindowgc. cwindowgc is the derived class of the image context cgraphicescontext class.
// Clear the content in the window
GC. setpenstyle (cgraphicscontext: enullpen );
GC. setbrushcolor (krgbgray );
GC. setbrushstyle (cgraphicscontext: esolidbrush );
GC. drawrect (rect ());
GC. setbrushstyle (cgraphicscontext: enullbrush );
 
// Draw the background of the customer Zone
GC. bitblt (rect (). ITL, ibackgroundimage );
// GC. drawbitmap (rect (), ibackgroundimage); // scale down the target rectangle by stretching

// Draw a bitmap icon in the first line of the customer area
// Draw a non-transparent bitmap and select a function without the word "Masked ".
Tpoint ptpos = rect (). ITL;
GC. bitblt (ptpos, iimage2); // keep the original size during painting

// To draw a transparent bitmap, you must have a corresponding mask. Only by combining the two can the screen be displayed successfully.
Tsize size = iimage2-> sizeinpixels ();
Trect sourcerect (tpoint (0, 0), size );
Ptpos. IX + = size. iwidth;
GC. bitbltmasked (ptpos, iimage2, sourcerect, iimage2mask, etrue );

// Draw a scaled-down transparent bitmap
Ptpos. IX + = size. iwidth;
Size. iwidth * = 2;
Size. iheight * = 2;
Trect destrect (ptpos, size );
GC. drawbitmapmasked (destrect, iimage2, sourcerect, iimage2mask, etrue );
E: Add Lib:

Library eikcoctl. Lib
Library bafl. Lib
Library charconv. Lib
Library fbscli. Lib
Library aknicon. Lib bitgdi. Lib mediaclientimage. Lib

There are two classes involved in this section that also involve the MMP file:

They are as follows:

1: MMP file:

 Targettestsvg_0xe6c3ff66.exe <br/> targettypeexe <br/> uid 0x100039ce 0xe6c3ff66 </P> <p> sourcepath .. /src <br/> sourcetestsvg. CPP <br/> sourcetestsvgapplication. CPP <br/> sourcetestsvgappview. CPP <br/> sourcetestsvgappui. CPP <br/> sourcetestsvgdocument. CPP </P> <p> sourcepath .. /Data </P> <p> Start resourcetestsvg. RSS <br/> header <br/> Target testsvg_0xe6c3ff66 <br/> targetpath resource/apps <br/> end // resource </P> <p> Start resourcetestsvg_reg.rss <br/> Target testsvg_0xe6c3ff66_reg <br/> targetpath/private/10003a3f/apps <br/> end // resource </P> <p> userinclude .. /INC <br/> userinclude .. /help </P> <p> systeminclude/epoc32/include </P> <p> library euser. lib <br/> library apparc. lib <br/> library cone. lib <br/> library eikcore. lib <br/> library avkon. lib <br/> library commonengine. lib <br/> library efsrv. lib <br/> library Estor. lib <br/> library aknnotify. lib <br/> library hlplch. lib <br/> library eikcoctl. lib <br/> library bafl. lib <br/> library charconv. lib <br/> library fbscli. lib <br/> library aknicon. lib bitgdi. lib mediaclientimage. lib </P> <p> Lang SC </P> <p> vendorid 0 <br/> SecureID 0xe6c3ff66 <br/> capability readuserdata </P> <p> # ifdef enable_abiv2_mode <br/> debuggable_udebonly <br/> # endif </P> <p> // BMP package resource command <br/> Start bitmap testsvg_bmp .mbm <br/> header <br /> targetpath/resource/apps <br/> sourcepath .. /picture/BMP <br/> source C24 image1.bmp <br/> source C24 image2.bmp <br/> source 1 image2_mask.bmp <br/> end <br/> // end of File

 

1: testsvgappview. h

# Ifndef _ testsvgappview_h__< br/> # DEFINE _ testsvgappview_h__</P> <p> // includes <br/> # include <coecntrl. h> </P> <p> // class declaration <br/> class ctestsvgappview: Public ccoecontrol <br/>{< br/> public: <br/> // new methods </P> <p>/** <br/> * newl. <br/> * two-phased constructor. <br/> * Create a ctestsvgappview object, which will draw itself to arect. <br/> * @ Param arect the rectangle this view wil L be drawn. <br/> * @ return a pointer to the created instance of ctestsvgappview. <br/> */<br/> static ctestsvgappview * newl (const trect & arect); </P> <p>/** <br/> * newlc. <br/> * two-phased constructor. <br/> * Create a ctestsvgappview object, which will draw itself <br/> * To arect. <br/> * @ Param arect rectangle this view will be drawn. <br/> * @ return a pointer to the created instance Ctestsvgappview. <br/> */<br/> static ctestsvgappview * newlc (const trect & arect); </P> <p>/** <br/> *~ Ctestsvgappview <br/> * virtual destructor. <br/> */<br/> virtual ~ Ctestsvgappview (); </P> <p> public: <br/> // functions from base classes </P> <p>/** <br/> * From ccoecontrol, draw <br/> * draw this ctestsvgappview to the screen. <br/> * @ Param arect the rectangle of this view that needs updating <br/> */<br/> void draw (const trect & arect) const; </P> <p>/** <br/> * From coecontrol, sizechanged. <br/> * called by framework when the view size is changed. <br/> */<br/> virtual void sizechanged (); </P> <p>/** <br/> * From coecontrol, handlepointereventl. <br/> * called by framework when a pointer touch event occurs. <br/> * Note: although this method is compatible with earlier sdks, <br/> * It will not be called in sdks without touch support. <br/> * @ Param apointerevent the information about this event <br/> */<br/> virtual void handlepointereventl (const tpointerevent & apointerevent ); </P> <p> PRIVATE: <br/> // constructors </P> <p>/** <br/> * constructl <br/> * 2nd phase constructor. <br/> * perform the second phase construction of a <br/> * ctestsvgappview object. <br/> * @ Param arect the rectangle this view will be drawn. <br/> */<br/> void constructl (const trect & arect); </P> <p>/** <br/> * ctestsvgappview. <br/> * C ++ default constructor. <br/> */<br/> ctestsvgappview (); <br/> PRIVATE: <br/> cfbsbitmap * ibackgroundimage; <br/> cfbsbitmap * iimage2; <br/> cfbsbitmap * iimage2mask; </P> <p> // cfbsbitmap * isoundsvg; // The image converts the SVG image into a bitmap. To achieve vector stretching, need to reload <br/> // cfbsbitmap * isoundsvgmask; <br/> }; </P> <p> # endif // _ testsvgappview_h__< BR/> // end of File

 

1: testsvgappview. cpp

# Include <coemain. h> <br/> # include "testsvgappview. H "</P> <p> # include <aknutils. h> // SWB <br/> # include <graphic_bmp .mbg> // SWB bitmap enumeration <br/> # include <akniconutils. h> // akniconutils class definition <br/> # include <graphic_svg.mbg> // bitmap enumeration </P> <p> _ resolve (ksvgpath, "// resource // apps // graphic_svg.mif"); <br/> _ partition (kbitmappath, "// resource // apps // graphic_bmp .mbm "); <br/> // ============================ ======= Member functions ===================================< /P> <p> // ------------------------------------------------------------------------------- <br/> // ctestsvgappview:: newl () <br/> // two-phased constructor. <br/> // comment <br/> // <br/> ctestsvgappview * ctestsvgappview: newl (const trect & arect) <br/> {<br/> ctestsvgappview * Self = Ctestsvgappview: newlc (arect); <br/> cleanupstack: Pop (Self); <br/> return self; <br/>}</P> <p> // snapshot <br/> // ctestsvgappview: newlc () <br/> // two-phased constructor. <br/> // comment <br/> // <br/> ctestsvgappview * ctestsvgappview: newlc (const trect & arect) <br />{< Br/> ctestsvgappview * Self = new (eleave) ctestsvgappview; <br/> cleanupstack: pushl (Self ); <br/> Self-> constructl (arect); <br/> return self; <br/>}</P> <p> // configure <br/> // ctestsvgappview: constructl () <br/> // Symbian 2nd phase constructor can leave. <br/> //------------------------------------------------------------------- ---------- <Br/> // <br/> void ctestsvgappview: constructl (const trect & arect) <br/>{< br/> // create a window for this application view <br/> createmediawl (); </P> <p> // set the Windows size <br/> setrect (arect); </P> <p> _ blank (kbitmappath, "// resource // apps // graphic_bmp .mbm "); </P> <p> ********************* **/<br/> tfilename bitmapfile (kbitmappath ); <br/> User: leaveiferror (completewithappp Ath (bitmapfile); </P> <p> ibackgroundimage = ieikonenv-> createbitmapl (bitmapfile, region); <br/> iimage2 = ieikonenv-> createbitmapl (bitmapfile, embmgraphic_bmp image2); <br/> iimage2mask = ieikonenv-> createbitmapl (bitmapfile, embmgraphic_bmp image2_mask ); </P> <p> // SVG <br/> // tfilename svgfile (ksvgpath); <br/> // User: leaveiferror (completewithapppath (svgfile )); </P> <p> // akniconu Tils: createiconl (isoundsvg, isoundsvgmask, svgfile, embmgraphic_svgsound, volume); <br/> // isoundsvg = akniconutils: createiconl (svgfile, volume ); <br/> // akniconutils: setsize (isoundsvg, tsize (50, 50), timeout); <br/> // akniconutils: setsize (isoundsvgmask, tsize (50, 50 ), easpectrationotpreserved ); <br/> // */<br/> /*************************** ******** * ******/<Br/> // activate the window, which makes it ready to be drawn <br/> activatel (); <br/>}</P> <p> // comment <br/> // ctestsvgappview: ctestsvgappview () <br/> // C ++ default constructor can not contain any code, that might leave. <br/> // ------------------------------------------------------------------------------- <br/> // <br /> Ctestsvgappview: ctestsvgappview () <br/>{< br/> // no implementation required <br/>}</P> <p> // response <br/> // ctestsvgappview ::~ Ctestsvgappview () <br/> // destructor. <br/> // configure <br/> // <br/> ctestsvgappview ::~ Ctestsvgappview () <br/>{< br/> // no implementation required </P> <p> Delete ibackgroundimage; <br/> Delete iimage2; <br/> Delete iimage2mask; </P> <p> // Delete isoundsvg; <br/> // Delete isoundsvgmask; <br/>}</P> <p> // drawing <br/> // ctestsvgappview: Draw () <br/> // draws the display. <br/> // configure <br/> // <br/> void ctestsvgappview: Draw (const trect &/* arect */) const <br/>{< br/> // get the standard graphics context <br/> cwindowgc & GC = systemgc (); </P> <p> // gets the control's extent <br/> trect drawrect (rect ()); </P> <p> // clears the screen <br/> GC. clear (drawrect); </P> <p> // implemented in the draw () function <br/> // draws a graph in the context class cwindowgc of the device drawing, cwindowgc is a derived class of the graphical context cgraphicescontext class <br/> // clear the content in the window <br/> GC. setpenstyle (cgraphicscontext: enullpen); <br/> GC. setbrushcolor (krgbgray); <br/> GC. setbrushstyle (cgraphicscontext: esolidbrush); <br/> GC. drawrect (rect (); <br/> GC. setbrushstyle (cgraphicscontext: enullbrush); </P> <p> // draws the background of the customer area <br/> GC. bitblt (rect (). ITL, ibackgroundimage); <br/> // GC. drawbitmap (rect (), ibackgroundimage ); // scale down the target rectangle by stretching </P> <p> // draw a bitmap icon in the first line of the customer area <br/> // draw a non-transparent bitmap, select a function without the word "Masked". <br/> tpoint ptpos = rect (). ITL; <br/> GC. bitblt (ptpos, iimage2); // keep the original size when drawing </P> <p> // draw a transparent bitmap with a corresponding mask, <br/> tsize size = iimage2-> sizeinpixels (); <br/> trect sourcerect (tpoint (0, 0), size ); <br/> ptpos. IX + = size. iwidth; <br/> GC. bitbltmasked (ptpos, iimage2, sourcerect, iimage2mask, etrue); </P> <p> // draws a scaled transparent bitmap <br/> ptpos. IX + = size. iwidth; <br/> size. iwidth * = 2; <br/> size. iheight * = 2; <br/> trect destrect (ptpos, size); <br/> GC. drawbitmapmasked (destrect, iimage2, sourcerect, iimage2mask, etrue ); <br/>/* <br/> // draw an SVG chart icon in line 5 of the customer's Zone <br/> // draw a non-transparent SVG chart <br/> ptpos = rect (). ITL; <br/> ptpos. iy ++ = 100; <br/> GC. bitblt (ptpos, isoundsvg); </P> <p> // draw a transparent SVG image <br/> tsize size2 = isoundsvg-> sizeinpixels (); <br/> trect sourcerect2 (tpoint (0, 0), size2); <br/> ptpos. IX + = size2.iwidth; <br/> GC. bitbltmasked (ptpos, isoundsvg, sourcerect2, isoundsvgmask, etrue ); <br/> */</P> <p >}</P> <p> // variable <br/> // ctestsvgappview: sizechanged () <br/> // called by framework when the view size is changed. <br/> // comment <br/> // <br/> void ctestsvgappview: sizechanged () <br/>{< br/> drawnow (); <br/>}</P> <p> // handle <br/> // ctestsvgappview: handlepointereventl () <br/> // called by framework to handle pointer touch events. <br/> // Note: although this method is compatible with earlier sdks, <br/> // it will not be called in sdks without touch support. <br/> // response <br/> // <br/> void ctestsvgappview: handlepointereventl (const tpointerevent & apointerevent) <br/>{</P> <p> // call base class handlepointereventl () <br/> ccoecontrol: handlepointereventl (apointerevent ); <br/>}< br/>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.