J2ME 处理图片半透明

来源:互联网 发布:大数据服务器搭建 编辑:程序博客网 时间:2024/04/30 00:35
/** * CreateAlphaImage() 绘制带半透明的图片 *  * @param alphaValue *            透明度,其取值如0x88FFFFFF,前两位十六进制表示透明度,88表示透明度为50%,如果是00表示全透明,FF表示不透明。 * @param srcImage *            需要画成半透明的图片 * @return Image 半透明处理后的图片 */private Image createAlphaImage(Image srcImage, int alphaValue) {int w = srcImage.getWidth();int h = srcImage.getHeight();int len = w * h;int srcRGB[] = new int[len];int dscRGB[] = new int[len];try {srcImage.getRGB(srcRGB, 0, w, 0, 0, w, h);} catch (Exception ex) {ex.printStackTrace();}for (int i = 0; i < len; i++) {if ((int) (srcRGB[i]) == 0x00FFFFFF) {dscRGB[i] = srcRGB[i];} else {dscRGB[i] = srcRGB[i] & alphaValue;}}return Image.createRGBImage(dscRGB, w, h, true);}


 

原创粉丝点击