zoukankan      html  css  js  c++  java
  • j2me之图片翻转和透明等的处理代码

    代码

    /**
    * 获得img的半透明图像
    *
    @param alpha :alpha通道值, 必须在0到255之间
    *
    * 注:在修改alpha值时,先用或运算 | 0xff000000 使其alpha为0xff。
    * 再执行且运算,使其alpha值变为所传参数alpha。
    */
    private Image createAlphaImage(Image img, int alpha)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);
    int temp = (alpha <<24) |0x00ffffff;
    for (int i =0; i < argb.length; i++) {
    argb[i]
    = (argb[i] |0xff000000) & temp;
    }
    return Image.createRGBImage(argb, width, height, true);
    }



    /**
    * 获得img的变色图像 -- 只用某些位的颜色
    * 比如:color = 0x00ff00. 则返回图像的色值为原来的green位的值。
    * 放开两条打印语句,可以清晰的看到色值变化情况。
    */
    private Image createColorImage(Image img, int color)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);

    for (int i =0; i < argb.length; i++) {
    // System.out.print(Integer.toHexString(argb[i]) + " , ");
    argb[i] = argb[i] & color;
    // System.out.println(Integer.toHexString(argb[i]));
    }
    return Image.createRGBImage(argb, width, height, false);
    }




    /**
    * 获得img的倒立图像(竖直翻转)
    */
    private Image createReversalImage(Image img)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);

    int[] argb2 =newint[width * height];
    int row =0;
    int column =0;
    int index =0;
    for (int i =0; i < argb.length; i++) {
    row
    = i / width;
    column
    = i % width;
    index
    = (height - row -1) * width + column;
    argb2[i]
    = argb[index] ;
    }
    return Image.createRGBImage(argb2, width, height, false);
    }

    /**
    * 获得img的水平翻转图像
    */
    private Image createMirrorImage(Image img)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);

    int[] argb2 =newint[width * height];
    int row =0;
    int column =0;
    int index =0;
    for (int i =0; i < argb.length; i++) {
    row
    = i / width;
    column
    = i % width;
    index
    = row * width + (width -1- column);
    argb2[i]
    = argb[index] ;
    }
    return Image.createRGBImage(argb2, width, height, false);
    }


    /**
    * 获得img逆时针转90度后的图像
    */
    private Image createImage_TRANS_ROT90(Image img)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);

    int[] argb2 =newint[width * height];
    int row =0;
    int column =0;
    int index =0;
    for (int i =0; i < argb.length; i++) {
    row
    = i / width;
    column
    = i % width;
    index
    = (width - column -1) * height + row;
    argb2[index]
    = argb[i] ;
    }
    return Image.createRGBImage(argb2, height, width, false);
    }


    /**
    * 获得img顺时针转90度后的图像(相当于逆时针转270度)
    */
    private Image createImage_TRANS_ROT270(Image img)
    {
    int width = img.getWidth();
    int height = img.getHeight();
    int[] argb =newint[width * height];
    img.getRGB(argb,
    0, width, 0, 0, width, height);

    int[] argb2 =newint[width * height];
    int row =0;
    int column =0;
    int index =0;
    for (int i =0; i < argb.length; i++) {
    row
    = i / width;
    column
    = i % width;
    index
    = column * height + height -1- row;
    argb2[index]
    = argb[i] ;
    }
    return Image.createRGBImage(argb2, height, width, false);
    }




  • 相关阅读:
    HTTP长连接、短连接使用及测试
    递归分治算法之二维数组二分查找(Java版本)
    Java二维数组的概念和使用方法
    java二维数组遍历
    HashMap多线程并发问题分析
    Linux 移动或重命名文件/目录-mv 的10个实用例子
    CSS fixed 定位元素失效的问题
    关于 JavaScript 中的继承
    React 虚拟 DOM 的差异检测机制
    下拉框中选项的快速定位
  • 原文地址:https://www.cnblogs.com/chaohi/p/1905931.html
Copyright © 2011-2022 走看看