概述
private Bitmap createInvertedImage(){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic_1);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
// 设置图片旋转
matrix.preScale(1, -1);
//设置图片的缩放比,长度缩小一半
matrix.postScale(1, 0.5f);
//图片向右倾斜
matrix.preSkew(-0.5f, 0);
//倒影图片
Bitmap invertedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,height,matrix,false);
//最后合成的图片
Bitmap finalInvertedBitmap = Bitmap.createBitmap(width+invertedBitmap.getWidth(), height+invertedBitmap.getHeight(), Config.ARGB_8888);
//构建画布,把倒影和原图先画在画布上
Paint paint = new Paint();
Canvas canvas = new Canvas(finalInvertedBitmap);
canvas.drawBitmap(bitmap, 0, 0, paint);
//设置倒影的透明度
paint.setAlpha(100);
canvas.drawBitmap(invertedBitmap, 0, height, paint);
//线性渐变
LinearGradient linearGradient = new LinearGradient(0, height, 0, finalInvertedBitmap.getHeight(), 0x70ffffff, 0x70ffffff, TileMode.MIRROR);
paint.setShader(linearGradient);
//不懂啥意思
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, finalInvertedBitmap.getHeight(), paint);
return finalInvertedBitmap;
}
最后
以上就是傻傻春天为你收集整理的android 图片倾斜倒影的全部内容,希望文章能够帮你解决android 图片倾斜倒影所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复