热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android3D相册项目,AndroidGallery实现3D相册(附效果图+Demo源码)

Editedbymythouhttp:www.cnblogs.commythoupublicbooleancreateReflectedForAdapter(){finalintr

//Edited by mythou

//http://www.cnblogs.com/mythou/

public boolean createReflectedForAdapter()

{

final int reflectionGap = 4;

final int Height = 200;

int index = 0;

for (Mapmap : list)

{

Integer id = (Integer) map.get("image");

// 获取原始图片

Bitmap originalImage = BitmapFactory.decodeResource(mContext.getResources(), id);

int width = originalImage.getWidth();

int height = originalImage.getHeight();

float scale = Height / (float)height;

Matrix sMatrix = new Matrix();

sMatrix.postScale(scale, scale);

Bitmap miniBitmap = Bitmap.createBitmap(originalImage, 0, 0,

originalImage.getWidth(), originalImage.getHeight(), sMatrix, true);

//是否原图片数据,节省内存

originalImage.recycle();

int mwidth = miniBitmap.getWidth();

int mheight = miniBitmap.getHeight();

Matrix matrix = new Matrix();

// 图片矩阵变换(从低部向顶部的倒影)

matrix.preScale(1, -1);

// 截取原图下半部分

Bitmap reflectionImage = Bitmap.createBitmap(miniBitmap, 0, mheight/2, mwidth, mheight/2, matrix, false);

// 创建倒影图片(高度为原图3/2)

Bitmap bitmapWithReflection = Bitmap.createBitmap(mwidth, (mheight + mheight / 2), Config.ARGB_8888);

// 绘制倒影图(原图 + 间距 + 倒影)

Canvas canvas = new Canvas(bitmapWithReflection);

// 绘制原图

canvas.drawBitmap(miniBitmap, 0, 0, null);

Paint paint = new Paint();

// 绘制原图与倒影的间距

canvas.drawRect(0, mheight, mwidth, mheight + reflectionGap, paint);

// 绘制倒影图

canvas.drawBitmap(reflectionImage, 0, mheight + reflectionGap, null);

paint = new Paint();

// 线性渐变效果

LinearGradient shader = new LinearGradient(0, miniBitmap.getHeight(), 0, bitmapWithReflection.getHeight()

+ reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);

paint.setShader(shader);

// 倒影遮罩效果

paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

// 绘制倒影的阴影效果

canvas.drawRect(0, mheight, mwidth, bitmapWithReflection.getHeight() + reflectionGap, paint);

ImageView imageView = new ImageView(mContext);

// 设置倒影图片

imageView.setImageBitmap(bitmapWithReflection);

imageView.setLayoutParams(new GalleryView.LayoutParams((int)(width * scale),

(int)(mheight * 3 / 2.0 + reflectionGap)));

imageView.setScaleType(ScaleType.MATRIX);

mImages[index++] = imageView;

}

return true;

}



推荐阅读
author-avatar
zhoujielcl_767
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有