设为首页 加入收藏

TOP

Android Gallery 3D效果
2014-11-24 07:34:57 来源: 作者: 【 】 浏览:0
Tags:Android Gallery 效果

Demo下载:GalleryFlow


具体下载目录在 /2013年资料/4月/22日/Android Gallery 3D效果



其实实现这个效果很简单,下面作一个简单的介绍


一,创建倒影效果


这个基本思路是:


1,创建一个源图一样的图,利用martrix将图片旋转180度。这个倒影图的高是源图的一半。


Matrix matrix = new Matrix();


// 1表示放大比例,不放大也不缩小。
// -1表示在y轴上相反,即旋转180度。
matrix.preScale(1, -1);


Bitmap reflectionBitmap = Bitmap.createBitmap(
srcBitmap,
0,
srcBitmap.getHeight() / 2, // top为源图的一半
srcBitmap.getWidth(), // 宽度与源图一样
srcBitmap.getHeight() / 2, // 高度与源图的一半
matrix,
false);



2,创建一个最终效果的图,即源图 + 间隙 + 倒影。


final int REFLECTION_GAP = 5;


Bitmap bitmapWithReflection = Bitmap.createBitmap(
reflectionWidth,
srcHeight + reflectionHeight + REFLECTION_GAP,
Config.ARGB_8888);


3,依次将源图、倒影图绘制在最终的bitmap上面。


// Prepare the canvas to draw stuff.
Canvas canvas = new Canvas(bitmapWithReflection);

// Draw the original bitmap.
canvas.drawBitmap(srcBitmap, 0, 0, null);

// Draw the reflection bitmap.
canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);


4,创建LinearGradient,从而给定一个由上到下的渐变色。


Paint paint = new Paint();
paint.setAntiAlias(true);
LinearGradient shader = new LinearGradient(
0,
srcHeight,
0,
bitmapWithReflection.getHeight() + REFLECTION_GAP,
0x70FFFFFF,
0x00FFFFFF,
TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));


// Draw the linear shader.
canvas.drawRect(
0,
srcHeight,
srcWidth,
bitmapWithReflection.getHeight() + REFLECTION_GAP,
paint);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android驱动使用JNI调用 下一篇Android系统HAL层开发,编译过程(h..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)