![]() ![]() |
|
j2me透明效果的设计 | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/4/18 14:41:54 文章录入:杜斌 责任编辑:杜斌 | |
|
|
透明效果的设计,是开发游戏以及UI的常谈话题,小弟整理了下关于透明效果的嗲们,有兴趣的朋友可以看看
srcRgbImage = new int[imgWidth * imgHeight]; // 获取原始图片的所有像素,参见MIDP APPI文档 srcImage.getRGB(srcRgbImage, 0, imgWidth, 0, 0, imgWidth, imgHeight); shadowRgbImage = new int[srcRgbImage.length]; System.arraycopy(srcRgbImage, 0, shadowRgbImage, 0, shadowRgbImage.length); // 渐变图片的所有像素已开始都是全透明的 for (int i = 0; i < shadowRgbImage.length; i++) { shadowRgbImage &= 0x00ffffff; } new Thread(this).start(); } public void paint(Graphics g) { g.setColor(0, 0, 0); g.fillRect(0, 0, w, h); // 绘制渐变图片 g.drawRGB(shadowRgbImage, 0, imgWidth, (w - imgWidth) / 2, (h - imgHeight) / 2, imgWidth, imgHeight, true); g.setColor(0, 255, 0); g.drawString("count=" + count, w / 2, 30, Graphics.HCENTER | Graphics.TOP); } public void run() { while (true) { boolean changed = false; // 改变渐变图片的每一个像素 for (int i = 0; i < shadowRgbImage.length; i++) { // 获取渐变图片的某一像素的alpha值 int alpha = (shadowRgbImage & 0xff000000) >>> 24; // 原始图片的对应像素的alpha值 int oldAlpha = (srcRgbImage & 0xff000000) >>> 24; if (alpha < oldAlpha) { // alpha值++ shadowRgbImage = ((alpha + 1) << 24) | (shadowRgbImage & 0x00ffffff); changed = true; } } try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } count++; repaint(); // 当所有像素的alpha值都达到原始值后,线程运行结束 if (!changed) { System.out.println("over"); break; } } } } |
|
![]() ![]() |