首页
互助圈
新手教程
进阶之路
算法原理
架构设计
JAVA进阶
C/C++进阶
Python进阶
JavaScript
数据库
大数据
消息服务
源码解读
JAVA源码
Spring源码
数据库
消息服务
Dubbo源码
面试指南
大厂专栏
面试技巧
面试经验
面试题库
开发资料
文档资料
工具软件
电子书籍
小牛导航
在线工具
登录
当前位置:
首页
>
工具软件
>
Image Reflection
>
使用案例
>
Create Image with Reflection
谭浩皛
2023-12-01
/**
* This code is courtesy of Neil Davies at http://www.inter-fuser.com
* @param context the current context
* @param originalImage The original Bitmap image used to create the reflection
* @return the bitmap with a reflection
*/
public
static
Bitmap createReflectedImage(Context context, 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;
类似资料:
相关阅读
相关文章
相关问答
快捷导航:
新手教程
算法原理
架构设计
Java进阶
数据库进阶
大厂专栏
面试经验
编程笔记
编程问答
所有专题
文档资料
工具软件
电子书籍
小牛导航
在线工具:
房贷计算器
个税计算器
Linux命令查询
Json格式化
正则表达式
颜色转换
AES加解密
SHA1加密
MD5加密
毒鸡汤
字数统计
随机密码生成
进制转换
Base64编解码
励志句子
Copyright © 2019-2024 小牛知识库@xnip.cn. All Rights Reserved.