📄 alphacanvas.java
字号:
/**源代码由程序员联合开发网(www.pudn.com)会员"周润发"收集、整理、重新编辑
*Email: ql_chuanzhang@tom.com
*QQ号:1103798882
*欢迎大家与我联系互相交流学习
**/
package AlphaPackage;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class AlphaCanvas extends Canvas implements Runnable {
private Image backgroundImage;
private int[] maskArray;
private int imageWidth;
private int imageHeight;
private int x;
private int y;
private int maskHeight = 0;
public AlphaCanvas(String imageName) {
//create the background image
try {
backgroundImage = Image.createImage(imageName);
}catch(IOException ioe) {
ioe.printStackTrace() ;
}
imageWidth = backgroundImage.getWidth();
imageHeight = backgroundImage.getHeight();
//create a semi-transparent red mask to cover the background image
maskArray = new int[imageWidth*imageHeight];
for (int i = 0; i < imageWidth*imageHeight; i++) {
maskArray[i] = 0x11FFF000;//alpha coefficient set to 0.3
}
x = (getWidth() - imageWidth)/2;
y = (getHeight() - imageHeight)/2;
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());//paint Canvas background white
g.drawImage(backgroundImage, x, y, Graphics.TOP|Graphics.LEFT);
//render the semi-transparent mask
if (maskHeight != 0){
g.drawRGB(maskArray, 0, imageWidth, x, y, imageWidth, maskHeight, true);
}
}
public void run() {
for(int i = 1; i <= imageHeight; i++) {
maskHeight = i;
repaint();
try {
Thread.sleep(50);
}catch(InterruptedException ie) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -