public static Bitmap createReflectedImage(Bitmap originalImage) {
// The gap we want between the reflection and the original image
final int reflectionGap = 4;
int width = originalImage.getWidth();
int height = originalImage.getHeight();
// This will not scale but will flip on the Y axis
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
// Create a Bitmap with the flip matrix applied to it.
// We only want the bottom half of the image
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width,
height / 2, matrix, false);
// Create a new bitmap with same width but taller to fit reflection
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2),
Config.ARGB_8888);
// Create a new Canvas with the bitmap that's big enough for
// the image plus gap plus reflection
Canvas canvas = new Canvas(bitmapWithReflection);
// Draw in the original image
canvas.drawBitmap(originalImage, 0, 0, null);
// Draw in the gap
Paint defaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
// Draw in the reflection
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
// Create a shader that is a linear gradient that covers the reflection
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff,
TileMode.CLAMP);
// Set the paint to use this shader (linear gradient)
paint.setShader(shader);
// Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
分享到:
相关推荐
android中对Bitmap图片设置任意角为圆角
Android不支持将Bitmap转换成单色的Bmp图片,所以参考Bmp格式说明,自己写了一个转换类。亲测有效!!!
主要介绍了Android 实现把bitmap图片的某一部分的颜色改成其他颜色,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Android图片Bitmap和字符串String之间相互转换的工具类,外加项目代码,封装好的,直接可以用,
NULL 博文链接:https://chen592969029.iteye.com/blog/749100
软件开发网在此之前给大家介绍过图片加载框架Glide的基本用法介绍,大家可以先参考一下,本篇内容更加深入的分析了Glide获取图片Path、Bitmap用法,以及实现的代码分析。 1. 获取Bitmap: 1)在图片下载缓存好之后...
android bitmap outofMemory 用来解决android中常见的bitmap outOfMemory
主要介绍了 Android canvas drawBitmap方法详解及实例的相关资料,需要的朋友可以参考下
Android中压缩bitmap的工具类,用于压缩bitmap图片用,适用于图片体积过大而同时显示等对图片质量要求不大的场景
Android bitmap Android Bitmap相关
android Bitmap圆角与倒影的具体实现代码,需要的朋友可以参考一下
这是一个用于Android网络图片下载及其处理的示例源代码,非常适合Android初级开发人员使用,尤其是对下载图片的缩放等进行了详细的示范,希望大家学以致用!
Android上解析24位深度Bitmap文件示例
Android中bitmap转化成string格式的工具类,主要用于联网操作传递数据情境中
android Bitmap相关知识介绍~~~
一个基于android平台Bitmap 工具类,一个基于android平台Bitmap 工具类,一个基于android平台Bitmap 工具类,一个基于android平台Bitmap 工具类,一个基于android平台Bitmap 工具类,一个基于android平台Bitmap 工具...
简介: 感觉Uri 、File、bitmap 比较混乱,这里...以选择一张图片为例: String path = FileTools.getRealPathFromUri(content,uri); //自定义方法在下面 public static String getRealPathFromUri(Context context,
实现了获取界面部分view,生成bitmap图片,也就是view截图,获取指定view的截图,适用于分享截图等
Android下使用Canvas生成验证码Bitmap