日期:2014-05-20  浏览次数:20741 次

j2me的屏幕内容可以缓存吗
最近做一个东东,对屏幕刷新要求比较高,要是能够把原来屏幕上的内容缓存下来, 下次画时就直接从缓冲区里面取(全部或部分),效率应当会高不少。
好象game包里的layer实际上是没有这个功能的?
有其他解决方案吗?

------解决方案--------------------
可以缓存,但面对的机型会有限制。
机型要求:
1.内存够用
2.支持MIDP2.0,要用drawRGB()
3.运行速度高

调用drawRGB花费的时间大概是15ms,如果你的优化算法做的好的话,一帧花费时间也就60ms以内,大多都是个25ms。
但这种做法有个问题,大多的烂机器都不能支持:比如moto(几乎全部),S40.

索爱和S60完全没问题,速度飞快
------解决方案--------------------
呵呵,好东东 ,能够说得详细些吗?具体怎么操作啊?为什么要使用drawRGB()?
------解决方案--------------------
还有一种方法是建立一个和屏幕大小一样的缓存,把你要画的东西先画到缓存里,然后再把缓存里的东西画到手机屏幕上,这个只是需要较大的内存,速度并不需要太快.
------解决方案--------------------
其实这个缓冲的功能要自己实现的,就是说自己维护一个屏幕这么大的Image对象
------解决方案--------------------
用buffer不就可以了,建立两个屏幕大小的buffer,然后互相拷贝就OK了.

------解决方案--------------------
好像Graphics没有提供readImage or readRGB函数来读出当前画的内容。

不过象楼上的几位已经说过,用一个自己的offscreen buffer来实现你所需要的

javax.microedition.lcdui.*;

public class gameCanvas extends Canvas
{
...
Image backBuffer;
Graphics backBufferGraphics;
...
public gameCanvas()
{
....
 // initialize the back-buffer to be the same dimension as the canvas,
 // and get the Graphics of the buffer for off-screen drawing
backBuffer = Image.createImage( getWidth(), getHeight() );
backBufferGraphics = backBuffer.getGraphics();
....
}
....
public void paint(Graphics g)
{
if(really need refresh)
{
...
// do all the Graphics drawing onto the back-buffer
backBufferGraphics.draw...
...
}

//如果不需要重画所有内容,直接把offscreen buffer画到screen即可
// now "flip" the back-buffer to the front 
// by drawing the whole back-buffer image onto the screen.
// since individual Graphics call is "double-buffered",
// this won't create any "tearing" on the screen.
g.drawImage( backBuffer, 0, 0 Graphics.TOP|Graphics.LEFT );
}
}
------解决方案--------------------
MIDP2.0用GAMECANVAS直接就使用的双缓存。