Symbian Programming Summary-graphic image article-use double cache for drawing

Source: Internet
Author: User

The so-called "double buffering" refers to the drawing is not directly painted on the screen, but in memory to open a buffer, in this buffer to complete all the drawings, directly to "paste" to the screen. Double buffering technology, because the majority of the drawing operation in memory, so the drawing speed is not too large constraints; In addition, when the complex drawing operations, the use of double buffering technology can effectively prevent the flicker of the screen.

The realization of double cache technology in J2ME

In J2ME, implementing a dual-cache drawing graph can be achieved by using the following steps:

First, you create a class member variable image object, which is the size of the screen size.

For example, if the screen size is 240*320, the following code is used to create:

private Image img;
img = Image.createImage(240, 320);

Creates a class member variable graphics object that points to an IMG Graphics object:

private Graphics g;
g = img.getGraphics();

The above IMG object is an in-memory buffer, and you can use any method to draw arbitrary images on class member G without having to handle the complex drawing process in the canvas repaint event.

In the canvas repaint method, the buffer image is drawn on the screen's GC:

protected void paint(Graphics g) {
g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
}

This completes the simple double cache implementation in the J2ME.

Two, double cache technology in Symbian's realization

There are two ways to implement dual Buffering technology in Symbian: We start with a simple approach.

The implementation of the first method is more close to the implementation in J2ME. In this method, a bitmap buffer object is also created in memory, and then the device context DC (similar to the graphics in J2ME) of the bitmap object is obtained, and the program can draw graphics for the DC of the memory buffer bitmap in any place Device. Within the Draw event (equivalent to the J2ME paint event), the buffer bitmap is drawn directly on the device's DC.

First, add the following definition to the header file:

CWsBitmap* iBufBmp;
CFbsBitmapDevice* iBufDevice;
CBitmapContext* iBufGc;

1) ibufbmp is a buffer bitmap object and is a cwsbitmap type. Class Cwsbitmap inherits from class Cfbsbitmap, the reason we use cwsbitmap here is because it is relatively fast and introduces the Cwsbitmap class in the SDK:

This is a bitmap to which the window server already has a handle. Functions

Which take a window server bitmap are faster than equivalent functions which

Take a cfbsbitmap.

2 Ibufdevice for Cfbsbitmapdevice types of objects, Cfbsbitmapdevice's official interpretation can be simply understood as a graphical device for managing text and bitmaps:

A graphics device to which a bitmap managed by the font and bitmap server can is drawn.

3 IBUFGC is a Cbitmapcontext type object, the device context DC of the bitmap object, after obtaining the IBUFGC, you can use the method in Cbitmapcontext to draw the bitmaps.

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.