📄 splashcanvas.java
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
class splashCanvas extends Canvas implements Runnable
{
private Image splash1, splash2, bufImage; /* Splash图片 */
private Graphics g;
private int[] rawInt1, rawInt2; // 保存图片的数组
private boolean isEnd;
public splashCanvas(Nikuman parent)
{
setFullScreenMode(true); //设置全屏
bufImage = Image.createImage(getWidth(), getHeight());
g = bufImage.getGraphics(); /* 获得显示图形 */
isEnd=false;
try
{
/* 加载图片 */
Image img = Image.createImage("/image/Splash.png");
splash1 = Image.createImage(img, 0, 0, 135, 85, 0);
splash2 = Image.createImage(img, 0, 85, 135, 88, 0);
}
catch(Exception e){}
rawInt1 = new int[splash1.getWidth() * splash1.getHeight()]; /* 获取第一张Splash界面 */
splash1.getRGB(rawInt1, 0, splash1.getWidth(), 0, 0, splash1.getWidth(), splash1.getHeight());
rawInt2 = new int[splash2.getWidth() * splash2.getHeight()]; /* 获取第二张Splash界面 */
splash2.getRGB(rawInt2, 0, splash2.getWidth(), 0, 0, splash2.getWidth(), splash2.getHeight());
Thread t = new Thread(this); /* 启动线程 */
t.start();
}
public void paint(Graphics g)
{
g.drawImage(bufImage, 0, 0, 0); // 画图
}
protected void keyPressed(int keyCode)
{
if(keyCode==-7)
//利用标志确定是否提前退出该线程
isEnd=true;
}
public void run()
{
/* 加载步骤:
*先用Alpha效果加载两次Splash图形
*再播放声音
*最后设置MIDP显示的Canvas
*/
draw(rawInt1, 0, 10, splash1, 1000);
draw(rawInt2, 0, 10, splash2, 1000);
Nikuman.disposeSplash();
}
//绘制Alpha图像
private void draw(int[] rawInt, int alpha, int value, Image img, int sleep)
{ // rawInt为图片数组,alpha为初始图片的alpha值,value为每次增加的alpha值
// img为原图像,sleep为停止时间
while(alpha >= 0&&!isEnd)
{
alpha += value;
if(alpha >= 255)
{
try{ Thread.sleep(sleep); }catch(Exception e){}
value = value * -1;
}
else
{
Fade(rawInt, alpha, 0xFFFFFFFF, 0xFFFFFFFF);
Image fadeImage = Image.createRGBImage(rawInt, img.getWidth(), img.getHeight(), true);
g.setColor(0xFFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(fadeImage, (getWidth()-fadeImage.getWidth())/2,
(getHeight()-fadeImage.getHeight())/2, 0);
try{ Thread.sleep(1); }catch(Exception e){}
}
repaint();
System.gc();
}
}
public void Fade(int[] raw, int alphaValue, int maskColor, int notMaskColor)
{
int len = raw.length;
for(int i=0; i<len; i++)
{
int a = 0;
int color = (raw[i] & 0x00FFFFFF); // 获得像素颜色
if(maskColor==color) a = 0;
else if(notMaskColor==color) a = 255;
else if(alphaValue>0) a = alphaValue; // 设置Alpha值
a = (a<<24); //将Alpha值左移24位,颜色为0xAARRGGBB
color += a;
raw[i] = color;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -