本文主要是介绍Android Bitmap 倒影,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
public Bitmap invertedImg() {//1. 倒立图Matrix matrix = new Matrix();matrix.preScale(1, -1);int w = mBitmap.getWidth();int h = mBitmap.getHeight();Bitmap reflectionImg = Bitmap.createBitmap(mBitmap, 0, h / 2, w, h / 2, matrix, false);//2. 要生成原图加倒立图,先生成一个可变的Bitmap,高度为1.5倍原hint gap = 10; //间隙 空白Bitmap newBitmap = Bitmap.createBitmap(w, h + h / 2 + gap, Bitmap.Config.ARGB_8888);Paint paint = new Paint();Canvas canvas = new Canvas(newBitmap);canvas.drawBitmap(mBitmap, 0, 0, paint); //绘制原图canvas.drawBitmap(reflectionImg, 0, h + gap, paint); //绘制倒立图//3. 画笔使用 LinearGradient 线性渐变渲染LinearGradient lg = new LinearGradient(0, h + gap, w, newBitmap.getHeight(), 0xabff0000,0x00ffff00, Shader.TileMode.MIRROR);paint.setShader(lg);//4. 指定画笔的Xfermode 即绘制的模式(不同的模式,绘制的区域不同)paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));//5. 在倒立图区,绘制矩形渲染图层canvas.drawRect(0, h + gap, w, newBitmap.getHeight(), paint);paint.setXfermode(null);return newBitmap;
}
这篇关于Android Bitmap 倒影的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!