RadialGradient环形渲染
2015-09-13 21:58
323 查看
public RadialGradient(float x, float y, float radius, int[] colors, float[] positions,Shader.TileMode tile)
float x: 圆心X坐标
float y: 圆心Y坐标
float radius: 半径
int[] colors: 渲染颜色数组floate[] positions: 相对位置数组,可为null, 若为null,可为null,颜色沿渐变线均匀分布
Shader.TileMode tile:[b]渲染器平铺模式[/b]
public RadialGradient(float x, float y, float radius, int color0, int color1,Shader.TileMode tile)
float x: 圆心X坐标
float y: 圆心Y坐标
float radius: 半径
int color0: 圆心颜色int color1: 圆边缘颜色
Shader.TileMode tile:[b]渲染器平铺模式[/b]
[b]主要代码:[/b]
public class RadialGradientActivity extends Activity { ImageView image,image2,image3,image4; int width,height; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView) findViewById(R.id.image); image2 = (ImageView) findViewById(R.id.image2); image3 = (ImageView) findViewById(R.id.image3); image4 = (ImageView) findViewById(R.id.image4); width = ValueUtil.dp2px(this, 120); height = ValueUtil.dp2px(this, 120); Bitmap bitmapTemp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapTemp); RadialGradient mShader = new RadialGradient(width/2, height/2,height/2, new int[]{ Color.RED, Color.GREEN, Color.BLUE}, null, Shader.TileMode.MIRROR); Paint paint = new Paint(); paint.setShader(mShader); canvas.drawCircle(width/2, height/2,height/2,paint); image.setImageBitmap(bitmapTemp); Bitmap bitmapTemp2 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas2 = new Canvas(bitmapTemp2); RadialGradient mShader2 = new RadialGradient(width/2, height/2,height/2, new int[]{ Color.RED, Color.GREEN, Color.BLUE}, null, Shader.TileMode.MIRROR); Paint paint2 = new Paint(); paint2.setShader(mShader2); canvas2.drawCircle(width / 2, height / 2 + 50, height / 2, paint2); image2.setImageBitmap(bitmapTemp2); Bitmap bitmapTemp3 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas3 = new Canvas(bitmapTemp3); RadialGradient mShader3 = new RadialGradient(width/2, height/2, 48, new int[] { 0x88ffffff, Color.TRANSPARENT },new float[]{0.01f,0.99f}, Shader.TileMode.REPEAT); Paint paint3 = new Paint(); paint3.setShader(mShader3); canvas3.drawRect(new RectF(0, 0, width, height), paint3); image3.setImageBitmap(bitmapTemp3); image3.setBackgroundResource(R.drawable.tupian); } }
效果图:
[b]
[/b]
[b]参考资料:/article/1875779.html[/b]
[b]/article/1875778.html
[/b]
[b]源码:http://yunpan.cn/c3f2qgcVtNSwP (提取码:2ccf)[/b]
相关文章推荐
- 虚数的图解
- 重拾java系列一java基础(3)
- Python进阶06 循环对象
- 每天一个linux命令(4):mkdir命令 http://www.cnblogs.com/younes/archive/2009/11/20/1607174.html
- Linux ELF File
- Unity Web Player修改加载页面的LOGO
- JavaScript设计模式——单体模式
- hdu 5444 Elven Postman(二叉树)
- 网页的加载渲染速度分析及网页支持程度和兼容性
- Git之添加远程库
- 实现跨平台的C++线程库
- 10020 - Minimal coverage(水题)
- 正确理解javascript当中的面向对象
- java笔记
- HDOJ problem1003(DP)
- hdu 5443 The Water Problem(水)
- 面试题总结1
- 矩阵分解(rank decomposition)文章代码汇总
- 编hadoop-1.X源代码
- 15_09_13 http常见错误