在Android中2D中实现对图片的倒影(2)

//这个为,封装的对外的接口.
//实现倒影首先 实现对图片的倒转...通过矩阵来实现.因为如果A点在图片的最左上角(0,0)
//倒转后 则坐标变为(0,height) 而最左下角由(0,height) 变为(0,0) 倒转关系为 (x,height-y)
// 把图片中的像素取出来,每行像素相同,不同的行根据height递增而alpha递减.(如果像素是RGB_8888编码方式的话
// 0x88ffffff 88就表示alpha值ff为完全不透明,00为完全透明 )
// y = mx+b
//y为某行的alpha值. m为height b为初始alpha值.
    public static Bitmap shadowFromBitmap(Bitmap src,int alphastart, float percent){
        int width = src.getWidth();
        int height = (int) (src.getHeight());
         float f[] = {1.0F,0.0F,0.0F,0.0F,-1.0F,height,0.0F,0.0F,1.0F};
        //这里实现倒转
        Matrix matrix = new Matrix();
          matrix.setValues(f);
          Bitmap bitmap = Bitmap.createBitmap(src, 0, 0,width, height, matrix, false);
        
       
          height = (int) (height*percent);
          int[] pixels = new int[width*height];
          bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        shadowFromPixels(pixels, width, height, alphastart);
       
        bitmap =Bitmap.createBitmap(pixels, width, height, Config.ARGB_8888);
        return bitmap;
    }
   
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsfxz.html