游戏中经常会用到半透明
效果。但MIDP1.0年代似乎只有Nokia和LG两家的扩展API给出了可以处理Alpha通道的API。在MIDP2.0下,我们可以用Image类提供的方法得到一个图片的半透明版本。
try { image=Image.createImage("/ken.png");//载入原图 } catch (IOException e) { } int[] argb=new int[image.getWidth()*image.getHeight()];//产生图片数据数组 image.getRGB(argb,0,image.getWidth(),0,0,image.getWidth(),image.getHeight());//得到ARGB矩阵 for(int i=0;i
运行的效果如下图:
这样就可以在游戏中实现半透明效果。加上你的天才
创意,游戏一定会变的更炫目!
本程序在eclipse3.0+eclipseme0.6+WTK2.2下测试通过。