Display bitmap and SVG
Package, load, and draw
Package bitmap resources:
First put the image in the specified folder, and then add the large package script to the program's MMP file (last before the end)
Start bitmap graphic_bmp .mbm
Header
Targetpath \ resource \ apps
Sourcepath .. \ picture \ BMP
Source C24 image1.bmp
Source C24 image2.bmp
Source 1 image2_mask.bmp
After re-compilation, the compiler will package the bitmap icon into graphic_bmp .mbm, and store the generated bitmap resource header file graphic_bmp .mbg to the SDK header file directory.
Package SVG graph resources:
Create an MK file and add the MK file of the SVG resource to the bld. inf file.
Add one sentence: gnumakefile graphic_svg.mk
After the code is re-compiled, the SVG image resource file graphic_svg.mif is generated. The generated SVG image resource header file graphic_svg.mbg is stored in the SDK header file directory.
Image loading process:
To draw an image in a program, first load the image from a multi-image resource file to the program memory to generate a bitmap object, and then draw the image in the program.
// Load the bitmap image
// Declaration part
Cfbsbitmap * ibackgroundimage;
Cfbsbitmap * iimage2;
Cfbsbitmap * iimage2mask;
// Each member variable loads a bitmap. in the program, the bitmap class cfbsbitmap object is to be drawn.
Add in header file
# Include <aknutils. h>
# Include <graphic_bmp .mbg> // bitmap Enumeration
// The implementation part is loaded into the bitmap constructl () function.
_ Partition (kbitmappath, "\ resource \ apps \ graphic_bmp .mbm ");
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 );
Embmgraphic_bmp image1 is the resource ID defined in the mbg file.
Enum tmbmgraphic_bmp
{
Embmgraphic_bmp image1,
Embmgraphic_bmp image2,
Embmgraphic_bmp image2_mask
};
Delete a bitmap object after use
// Delete it from the destructor
Delete ibackgroundimage;
Delete iimage2;
Delete iimage2mask;
// Load the SVG Image
// Declaration part
Cfbsbitmap * isoundsvg; // The image converts the SVG image to a bitmap. To achieve vector stretching, reload the image.
Cfbsbitmap * isoundsvgmask;
// Implementation
# Include <akniconutils. h> // definition of the akniconutils class
# Include <graphic_svg.mbg> // bitmap Enumeration
_ Partition (ksvgpath, "\ resource \ apps \ graphic_svg.mif ");
// Load the SVG vector graph
Tfilename svgfile (ksvgpath );
User: leaveiferror (completewithapppath (svgfile ));
Akniconutils: createiconl (isoundsvg, isoundsvgmask, svgfile, embmgraphic_svgsound, embmgraphic_svgsound_mask );
// Isoundsvg = akniconutils: createiconl (svgfile, embmgraphic_svgsound );
Akniconutils: setsize (isoundsvg, tsize (50, 50), easpectrationotpreserved );
Akniconutils: setsize (isoundsvgmask, tsize (50, 50), easpectrationotpreserved );
// Delete after use
Delete isoundsvg;
Delete isoundsvgmask;
Image Display process:
// Implemented in the draw () function
Draws a graph in the device drawing context class cwindowgc. cwindowgc is a derived class of the graphic context class cgraphicescontext.
// Clear the content in the window
GC. setpenstyle (cgraphicscontext: enullpen );
GC. setbrushcolor (krgbgray );
GC. setbrushstyle (cgraphicscontext: esolidbrush );
GC. drawrect (arect );
GC. setbrushstyle (cgraphicscontext: enullbrush );
// Draw the background of the customer Zone
// GC. bitblt (rect (). ITL, ibackgroundimage );
GC. drawbitmap (arect, 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 = arect. 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 );
// Draw an SVG chart icon in line 2 of the customer's Zone
// Draw a non-transparent SVG Image
Ptpos = arect. ITL;
Ptpos. Iy + = 100;
GC. bitblt (ptpos, isoundsvg );
// Draw a transparent SVG Image
Tsize size2 = isoundsvg-> sizeinpixels ();
Trect sourcerect2 (tpoint (0, 0), size2 );
Ptpos. IX + = size2.iwidth;
GC. bitbltmasked (ptpos, isoundsvg, sourcerect2, isoundsvgmask, etrue );
Special Effect Drawing:
// No blinking re-painting
Program refreshing may flash when there are a lot of drawing operations
In Symbian, a drawing context device provided for the window client area is used for Screen Drawing, and a bitmap device is also provided.
The bitmap device actually points to a bitmap object in the content. Through the context of the bitmap device, you can directly draw the image on the in-place graph, that is, drawing directly in the memory through program code, copy the drawn bitmap to the customer area of the window.
Steps:
1) declare in the header file of the container
Cfbsbitmap * ioffscreenbitmap;
Cfbsbitmapdevice * ioffscreenbitmapdevice;
Cfbsbitgc * ioffscreenbitmapgc;
Cfbsbitmap * isoundsvg;
2) define bitmap and bitmap devices used for background painting, bitmap context // constructl ()
// Load the SVG vector graph
Tfilename svgfile (ksvgpath );
User: leaveiferror (completewithapppath (svgfile ));
Isoundsvg = akniconutils: createiconl (svgfile, embmgraphic_svgsound );
Akniconutils: setsize (isoundsvg, tsize (50, 50), easpectrationotpreserved );
// Create an off-screen bitmap, a bitmap device, and a bitmap device context
Ioffscreenbitmap = new (eleave) cfbsbitmap (); // create an empty bitmap
Cleanupstack: pushl (ioffscreenbitmap );
User: leaveiferror (ioffscreenbitmap-> Create (rect (). Size (), ecolor4k); // the size of the bitmap is set to the same size as that of the client.
Cleanupstack: Pop ();
Ioffscreenbitmapdevice = cfbsbitmapdevice: newl (ioffscreenbitmap); // create a bitmap Device
Ioffscreenbitmapdevice-> createcontext (ioffscreenbitmapgc); // create the context of the bitmap device.
3) add it to the destructor
Delete ioffscreenbitmapgc;
Ioffscreenbitmapgc = NULL;
Delete ioffscreenbitmapdevice;
Ioffscreenbitmapdevice = NULL;
Delete ioffscreenbitmap;
Ioffscreenbitmap = NULL;
4) Draw a chart on the in-place Graph
// Clear the background of the bitmap device.
Ioffscreenbitmapgc-> setpenstyle (cgraphicscontext: enullpen );
Ioffscreenbitmapgc-> setbrushcolor (krgbgray );
Ioffscreenbitmapgc-> setbrushstyle (cgraphicscontext: esolidbrush );
Ioffscreenbitmapgc-> drawrect (arect );
Ioffscreenbitmapgc-> setpenstyle (cgraphicscontext: esolidpen );
Ioffscreenbitmapgc-> drawellipse (rect ());
Ioffscreenbitmapgc-> bitblt (arect. ITL, isoundsvg );
// Takes charge of the drawing in the bitmap to the client area of the program window
Cwindowgc & GC = systemgc ();
GC. bitblt (rect (). ITL, ioffscreenbitmap );
Effect
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/linzhiji/archive/2010/01/29/5270522.aspx