生成带有透明渐变倒影的图片

来源:互联网 发布:linux 用代码链接网络 编辑:程序博客网 时间:2024/04/29 20:33
//生成带有倒影的图片public void createReflectedBitmap() {private int[] imageIds = new int[]{ R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6, R.drawable.photo7,                  R.drawable.photo8int ReflectionGap = 4;//原图片于倒影之间的距离int index = 0;for(int imageId : imageIds){//源图片Bitmap resourceBitmap = BitmapFactory.decodeResource(context.getResources(), imageId);int width = resourceBitmap.getWidth();int height = resourceBitmap.getHeight();//生成倒影图片//Bitmap source 源图片//x,y 生成倒影图片的起始位置  左上角//width,height 图片的宽高// Matrix m 用来 设置图片的样式 (倒影)Matrix matrix = new Matrix();// x水平翻转     y垂直翻转    1 正常     -1翻转matrix.setScale(1, -1); Bitmap refrectionBitmap = Bitmap.createBitmap(resourceBitmap, 0, height/2, width, height/2, matrix, false);//带有倒影的图片Bitmap bitmap = Bitmap.createBitmap(width, height + height/2, Config.ARGB_8888);//创建画布 Canvas canvas = new Canvas(bitmap);//绘制源图片canvas.drawBitmap(resourceBitmap, 0, 0, null);//绘制   原图片于倒影之间的距离Paint defaultPaint = new Paint();canvas.drawRect(0, height, width, height + ReflectionGap, defaultPaint);//绘制倒影图片canvas.drawBitmap(refrectionBitmap, 0, height + ReflectionGap, null);// ps中  渐变  遮罩Paint paint = new Paint();//遮罩paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));//渐变//0x70ffffff, 0x00ffffff/* * //线性渐变填充 shader着色器//在位图上Y方向花砖模式 TileMode:(一共有三种) CLAMP :如果渲染器超出原始边界范围,会复制范围内边缘染色。 REPEAT :横向和纵向的重复渲染器图片,平铺。 MIRROR :横向和纵向的重复渲染器图片,这个和REPEAT 重复方式不一样,他是以镜像方式平铺。 */LinearGradient shader = new LinearGradient(0, height, 0, bitmap.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.CLAMP);//着色器   用来绘制颜色  上色的paint.setShader(shader);canvas.drawRect(0, height, width, bitmap.getHeight(), paint);//加入图片ImageView imageView = new ImageView(context);// imageView.setImageBitmap(resourceBitmap);BitmapDrawable bd = new BitmapDrawable(bitmap);bd.setAntiAlias(true);//消除图片锯齿效果  平滑imageView.setImageDrawable(bd);//设置图片的大小imageView.setLayoutParams(new GalleryFlow.LayoutParams(160,240));images[index++] = imageView;}}


转自:http://www.apkbus.com/home.php?mod=space&uid=121336&do=blog&id=57992

0 0
原创粉丝点击