To make the Graphics 2D API portable across platform, the API is designed indepandant on any native graphics system (like LCDUI or LWUIT etc). It's "Canvas" actaully is a 2 demension integer arrary.
The constructor Graphics2D(int width,int height) creates an internal buffer of type 32-bit integer ,each element is a ARGB value ,stand for one pixel.
All the drawing primitives like draw a line, fill a rectange etc is actually modifying pixel (ARGB value) in the 2 demesional array.
After all rendering work is done, call Graphics2D.getRGB() to get the int [] buffer, and then call any native render method to actually render the buffer to the physical device screen.
so typical usage of Graphics 2D API is as following
Graphics2D graphics2d=new Graphics2D(width,height)
graphics2d.clear(backgroundColor)
...any render primitives
int []rgb=graphics2d.getRGB();
//call native graphics to render the buffer to screen
graphics.drawImage(rgb, ...);

No comments:
Post a Comment