Android学习研究(二)之BitmapShader
来源:互联网 发布:数据库创建索引规则 编辑:程序博客网 时间:2024/05/25 08:12
BitmapShader用于绘制位图作为纹理的着色器。通过设置平铺模式可以重复或镜像位图。我们会经常用它来实现圆形图片或圆角图片.今天研究一下BitmapShader的用法
BitmapShader的构造方法有三个参数:
1,Bitmap bitmap:位图
2, Shader.TileMode tileX: The tiling mode for x to draw the bitmap in. 在位图x轴显示的方式
3,Shader.TileMode tileY: The tiling mode for y to draw the bitmap in. 在位图y轴显示的方式
Shader.TileMode是一个枚举,有三种方式:
1,Shader.TileMode CLAMP replicate the edge color if the shader draws outside of its original bounds 如果着色器绘制出其原来的边界,复制边缘颜色 其实就是拉伸 但这个拉伸和屏保拉伸不一样,
这个不拉伸图片而是拉伸图片最后的那一个像素;横向的最后一个横行像素,不断的重复,纵项的那一列像素,不断的重复;
2,Shader.TileMode MIRROR repeat the shader’s image horizontally and vertically, alternating mirror images so that adjacent images always seam 重复着色器的图像水平和垂直,交替镜像图像,使相邻的图像总是接缝 实现的镜像效果;
3,Shader.TileMode REPEAT repeat the shader’s image horizontally and vertically 水平和垂直重复着色器的图像 重复效果;
1,CLAMP效果:
大图片:
小图片:
2,MIRROR效果:
3,REPEAT效果:
具体实现代码:
public class BitmapShaderView extends View { private Paint mPaint; public BitmapShaderView(Context context) { this(context,null); } public BitmapShaderView(Context context, AttributeSet attrs) { this(context, attrs,0); } public BitmapShaderView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initPaint(); } private void initPaint(){ mPaint = new Paint(); /** * bitmapshader */ Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.childinfo_good_state); BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR); mPaint.setShader(bitmapShader); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); /** * bitmapshader */ canvas.translate(getWidth()/2,getHeight()/2); canvas.drawCircle(0,0,500,mPaint); }}
- Android学习研究(二)之BitmapShader
- Android学习笔记进阶16之BitmapShader
- Android学习笔记进阶16之BitmapShader
- Android学习笔记进阶16之BitmapShader
- Android学习研究(五)通过BitmapShader实现圆形图片
- android--BitmapDrawable之BitmapShader
- Android 绘图Shader之BitmapShader
- Android BitmapShader
- HLSL 研究学习 之二
- HLSL 研究学习 之二
- Android Paint 之 BitmapShader位图的图像渲染器
- shader初探之BitmapShader
- Shader 之 BitmapShader
- android-graphics--BitmapShader译
- android BitmapShader类
- Android CTS 测试研究之二
- Android CTS 测试研究之二
- android Application Component研究之Activity(二)
- ARM体系架构
- Java Scoket网络编程,转自commandingofficer的博客(http://blog.sina.com.cn/s/blog_616e189f0100s3px.html)
- eclipse常用设置
- 获取当前Java对象的类型的工具类
- Mysql 如何设置字段自动获取当前时间
- Android学习研究(二)之BitmapShader
- 浅谈 Linux 系统中的 SNMP Trap 【转】
- 【网络相关】ip地址重定向
- Android在BroadcastReceiver中通过接口回调更新界面
- Spring依赖注入的方法
- 检验分类
- logger-library
- 你不知道的console。很有用处
- Linux在目录中进入目录创建文件需要哪些权限