Use caching in J2ME to store screen content as image

Source: Internet
Author: User

This article describes how to store the contents of the phone screen as an image object, where it is thought that a canvas is displayed on the phone screen. The idea of completing this function is to use a buffering mechanism. We can't get the pixels on the canvas directly, so we can't get the image object directly from the content on canvas. Convert the idea, if you want to draw the contents of the canvas first to a image, and this image does not appear on the screen, but only after the painting is completed one-time display to the screen. Experienced friends must have a double buffering mechanism, but here is not to use double buffering to solve the problem of the splash screen, but to get the current canvas content.

Let's write a simple canvas class to test the idea that Simplecanvas is a subclass of canvas, in order to preserve canvas content, we create an image that is the same size as the canvas.

Class Simplecanvas extends canvas{
int W;
int h;
Private Image offimage = null;
Private Boolean buffered = true;
Public Simplecanvas (Boolean _buffered) {
buffered = _buffered;
W = getwidth ();
h = getheight ();
if (buffered)
Offimage = Image.createimage (w,h);
}
protected void Paint (Graphics g) {
int color = G.getcolor ();
G.setcolor (0xFFFFFF);
G.fillrect (0,0,W,H);
G.setcolor (color);
Graphics save = g;
if (offimage!= null)
g = Offimage.getgraphics ();
Draw the Offimage
G.setcolor (128,128,0);
G.fillroundrect ((w-100)/2, (h-60)/2,100,60,5,3);
Draw the offimage to the canvas
Save.drawimage (offimage,0,0,graphics.top| Graphics.left);
}
Public Image Printme () {
return offimage;
}

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.