美文网首页
图片 倒影效果

图片 倒影效果

作者: 尔乐 | 来源:发表于2016-08-04 16:35 被阅读21次

public boolean createReflectedImages() {

final int reflectionGap =4;//原图与倒影之间的间隙

int index =0;

for(Map map : list) {

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

Bitmap originalImage = BitmapFactory.decodeResource(

mContext.getResources(),id);// 获得图片资源

// 获得图片的长宽

int width = originalImage.getWidth();

int height = originalImage.getHeight();

Matrix matrix =newMatrix();

matrix.preScale(1,-1);// 实现图片的反转

Bitmap reflectionImage = Bitmap.createBitmap(originalImage,0,

height /2,width,height /2,matrix, false);// 创建反转后的图片Bitmap对象,图片高是原图的一半

Bitmap bitmapWithReflection = Bitmap.createBitmap(width,

(height + height /2),Config.ARGB_8888);// 创建标准的Bitmap对象,宽和原图一致,高是原图的1.5倍

Canvas canvas =newCanvas(bitmapWithReflection);

canvas.drawBitmap(originalImage,0,0, null);// 创建画布对象,将原图画于画布,起点是原点位置

Paint paint =newPaint();

canvas.drawRect(0,height,width,height + reflectionGap,paint);

canvas.drawBitmap(reflectionImage,0,height + reflectionGap, null);// 将反转后的图片画到画布中

paint =newPaint();

LinearGradient shader =newLinearGradient(0,

originalImage.getHeight(),0,

bitmapWithReflection.getHeight() + reflectionGap,

0x70ffffff,0x00ffffff,TileMode.MIRROR);// 创建线性渐变LinearGradient对象

paint.setShader(shader);// 绘制

paint.setXfermode(newPorterDuffXfermode(Mode.DST_IN));//倒影遮罩效果

canvas.drawRect(0,height,width,bitmapWithReflection.getHeight()

+ reflectionGap,paint);// 画布画出反转图片大小区域,然后把渐变效果加到其中,就出现了图片的倒影效果

ImageView imageView =newImageView(mContext);

imageView.setImageBitmap(bitmapWithReflection);// 设置带倒影的Bitmap

//设置ImageView的大小,可以根据图片大小设置

// imageView.setLayoutParams(newmyGallery.LayoutParams(width,height));

imageView.setLayoutParams(newmyGallery.LayoutParams(250,500));//设置ImageView的大小,可根据需要设置固定宽高

imageView.setScaleType(ScaleType.FIT_CENTER);//将图片按比例缩放

mImages[index++] = imageView;

}

return true;

}

相关文章

  • 图片 倒影效果

    public boolean createReflectedImages() { final int reflec...

  • Quartz2D之倒影效果

    先来看一下倒影的效果,从效果图中可以看出好像图片的下方是图片本身在水中的倒影。其实真正实现起来很简单,核心...

  • android案例---图片处理倒影效果

    今天记录下看到的一个图片处理倒影效果,方便以后用到 先看看效果 as截出来的图貌似都挺大的 ok,那我们现在来分析...

  • 文字和图片的倒影效果

    倒影的实现语言:-webkit-box-reflect: below 10px -webkit-linear-gr...

  • 图片倒影

    方法一 将图片添加到两个相同的layer上 对要倒影的结果layer 进行180度旋转 使用渐变图层进行颜色处理 ...

  • Android图片处理(进阶)

    示例图 如图,将上述图片处理成各种样式 将彩色图片转化为灰图 将图片转成圆角图 图片添加倒影效果 添加水印 Vie...

  • css

    图像倒影 鼠标滑过按钮 css3图片动画效果 背景色 多类选择器(.className1.className2)不...

  • iOS 倒影效果自然倒影斜切透视

    前言 整理总结一下之前做的倒影相关操作,记录讲解一下整体思路 API & Property kj_initWith...

  • CSS3补充

    椭圆边框3 阴影 倒影效果

  • 水倒影效果制作

    找到一张合适的水面波纹图片,或者自己制作一张,保存为psd格式,然后把要制作倒影的图层用滤镜-模糊-动态模糊效果处...

网友评论

      本文标题:图片 倒影效果

      本文链接:https://www.haomeiwen.com/subject/gxocsttx.html