📄 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;
private Graphics g;
private int[] rawInt1, rawInt2;
public SplashCanvas() {
setFullScreenMode(true);
bufImage = Image.createImage(getWidth(), getHeight());
g = bufImage.getGraphics();
try {
Image img = Image.createImage("/Image/splash.png");
splash1 = Image.createImage(img, 0, 0, 135, 88, 0);
splash2 = Image.createImage(img, 0, 88, 135, 85, 0);
} catch(Exception e){}
rawInt1 = new int[splash1.getWidth() * splash1.getHeight()];
splash1.getRGB(rawInt1, 0, splash1.getWidth(), 0, 0, splash1.getWidth(), splash1.getHeight());
rawInt2 = new int[splash2.getWidth() * splash2.getHeight()];
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);
}
public void run() {
draw(rawInt1, 0, 15, splash1, 2000);
draw(rawInt2, 0, 15, splash2, 2000);
Start.disposeSplash();
}
protected void keyPressed(int keyCode)
{
if(keyCode!=0)
Start.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) {
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(5); }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 + -