⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alpha.java

📁 手机上实现Alpha混合的例子
💻 JAVA
字号:
import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Alpha extends Canvas implements Runnable{
	
	Image img;
	int imgWidth,imgHeigh;
	int width,heigh;
	int isUp;
	int alphaValue;
	
	Alpha()
	{
		try {
			img=Image.createImage("/board.PNG");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		imgWidth=img.getWidth();
		imgHeigh=img.getHeight();
		width=this.getWidth();
		heigh=this.getHeight();
	}
	
	Image getAlphaMixImage(Image img,int alpha)
	{
		int RGB[]=new int[imgWidth*imgHeigh];
		
		img.getRGB(RGB, 0, imgWidth, 0, 0, imgWidth, imgHeigh);
		for(int i=0;i<RGB.length;i++)
		{
			RGB[i]=RGB[i]&0x00ffffff;
			RGB[i]=RGB[i]|(0x01000000*alpha);
		}
		
		return Image.createRGBImage(RGB, imgWidth, imgHeigh, true);
	}

	protected void paint(Graphics g) {
		// TODO Auto-generated method stub
		g.setColor(0);
		g.fillRect(0, 0, width, heigh);
		
		Image imgTemp;
		imgTemp=this.getAlphaMixImage(img, alphaValue);
		
		g.drawImage(imgTemp, 0, 0, Graphics.TOP|Graphics.LEFT);

	}

	public void run() {
		// TODO Auto-generated method stub
		while(true)
		{
			if(alphaValue<255 && isUp==0)
			{
				alphaValue+=3;
			}
			else if(alphaValue>0 && isUp==1)
			{
				alphaValue-=3;
			}
			else
			{
				if(isUp==0)
				{
					isUp=1;
					//System.out.println(isUp);
				}
				else if(isUp==1)
					isUp=0;
			}
			//System.out.println(alphaValue);
			try {
				Thread.sleep(120);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			this.repaint();
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -