最简单的实现圆形图片的方式
2015-02-06 11:21
375 查看
很多demo中实现圆形图片的方面都使用了Xfermod,目前对Xfermod还不熟悉根据http://blog.csdn.net/sjf0115/article/details/7267532这篇文章中的思路,简单修个了下,
使用BitmapShader这种方式更好理解一些.github地址
使用BitmapShader这种方式更好理解一些.github地址
package com.example.circle; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.view.View; public class SimpleCircularImage extends View { private BitmapShader bitmapShader = null; private Bitmap bitmap = null; private ShapeDrawable shapeDrawable = null; private int width = 0; public SimpleCircularImage(Context context) { super(context); bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.head)).getBitmap(); width = Math.min(bitmap.getWidth(), bitmap.getHeight()); bitmapShader = new BitmapShader(bitmap,Shader.TileMode.CLAMP,Shader.TileMode.CLAMP); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //将图片裁剪为椭圆形 shapeDrawable = new ShapeDrawable(new OvalShape()); //得到画笔并设置渲染器 shapeDrawable.getPaint().setShader(bitmapShader); //设置显示区域 shapeDrawable.setBounds(0, 0,width,width); //绘制shapeDrawable shapeDrawable.draw(canvas); } }
相关文章推荐
- android,侧滑栏SlidingLayout、ViewPager实现画廊、简单用viewpager实现画廊、圆形图片、简单的跑马灯动画效果、可拖拽的弹簧式水泡动画集合
- 实现图片Bitmap简单编辑的三种方式
- android RoundedBitmapDrawable最简单方式实现圆角图片(一)
- java swing实现简单图片显示(测试生成图片快捷方式)
- <Unity3D UGUI>用UGUI方式实现图片的遮罩,圆角图片,圆形图片效果
- Android动态图片选择的一种简单实现方式
- 简单的图片翻转实现方式
- 完全封装简单的实现图片的圆形剪切效果
- android两种方式实现圆形图片
- iOS 上传图片到服务器 最简单的实现方式
- [置顶] 实现CirleImageView圆形图片的多种方式
- 将UIView的子类变为圆形的简单实现方式(圆形头像、圆形按钮)
- android 圆形图片多种实现方式
- 自定义圆形图片ImageView的简单实现效果
- 关于上报错误最简单的实现方式--利用图片
- 在Android中如何使用clipPath()方法实现简单的裁剪圆形图片
- CircularProgressBar - 以最简单的方式实现圆形ProgressBar
- 两种方式实现圆形图片
- Android中将方形图片截取成圆形的两种实现方式
- qici引擎简单实现圆形化图片操作