首页
Linux教程
Linux资讯
Linux入门
Linux运维
Linux系统
Linux服务器
Linux安全
Linux问答
SHELL
树莓派
正则
linux命令
安装
Linux监控
运维自动化
Ansible
Piwik
CentOS
Deepin
Ubuntu
Debian
FreeBSD
Nginx
Apache
openresty
Tengine
宝塔
SSH
页面位置:
Linuxboy
>
Linux教程
>
正文
android开发
Android给bitmap图加上倒影效果
文章由LinuxBoy分享于2019-04-01 02:04:07
热评(303)
Android给bitmap图加上倒影效果
Android给bitmap图加上倒影效果:
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 Activity返回结果startActivityForResult函数
Android TabHost风格
Android中隐藏标题栏和状态栏(电源,信号,时间等信息
Android编程动态创建视图View的方法
Android:键盘挡住输入框解决办法
Android结束系统中其他进程
Android自定义TabHost扩展控件TabView
Android Jni NDK 操作介绍
Android框架简介
Android使用JNI实现Java与C之间传递数据
今日最新
推荐文章:
Android Activity返回结果startActivityForResult函数
Android TabHost风格
Android中隐藏标题栏和状态栏(电源,信号,
Android编程动态创建视图View的方法
Android:键盘挡住输入框解决办法
Android结束系统中其他进程
评论暂时关闭
最新Linux教程教程
Android给bitmap图加上倒影效果
Android Activity返回结果startActivi
Android TabHost风格
Android中隐藏标题栏和状态栏(电
Android编程动态创建视图View的方
Android:键盘挡住输入框解决办法
Linux头条
Linux查看CPU和内存使用情况
Ubuntu console登录前显示IP地址
Linux下修改ulimit设置的最大进程
[翻译]Ubuntu 14.04, 13.10 下安装 O
linux库技术文档学习笔记
在802.11n无线LAN上实现视频传输
评论暂时关闭