自定义组件一
2016-07-11 21:53
246 查看
Paint
类表示画笔,用来描述图形的颜色和风格,如线宽、颜色、透明度和填充效果等信息。
使用Paint类时,需要先创建该类的对象,这可以通过该类提供的构造方法来实现,通常情况下,只需要使用Paint()方法来创建一个使用默认设置Paint对象。
使用Paint可以基本分为三步:
1.通过构造方法创建出一个Paint的实例出来;
2.通过各类set方法对该Paint对象进行设置;
3.通常搭配Canvas来使用Paint
实际使用例子:
首先,在布局中添加ImageView控件
在main中创建画笔
创建一个矢量图bitmap
አֵ
类表示画笔,用来描述图形的颜色和风格,如线宽、颜色、透明度和填充效果等信息。
使用Paint类时,需要先创建该类的对象,这可以通过该类提供的构造方法来实现,通常情况下,只需要使用Paint()方法来创建一个使用默认设置Paint对象。
使用Paint可以基本分为三步:
1.通过构造方法创建出一个Paint的实例出来;
2.通过各类set方法对该Paint对象进行设置;
3.通常搭配Canvas来使用Paint
实际使用例子:
首先,在布局中添加ImageView控件
<ImageView android:id="@+id/imageview" android:layout_width="300px" android:layout_height="300px" />
在main中创建画笔
创建一个矢量图bitmap
setContentView(R.layout.activity_main); // 创建画笔 Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // 创建一个矢量图(宽,高,设置(满饱和度)) Bitmap bitmap = Bitmap.createBitmap(600,600, Bitmap.Config.ARGB_8888); // 创建一个画布 Canvas canvas = new Canvas(bitmap); paint.setColor(Color.BLUE); // 绘图的结果最后都会保留在bitmap中(圆心坐标(x,y),圆弧半径长度) canvas.drawCircle(100, 100, 100, paint); // 拿到imageView视图,并设置他的图片为刚才的图片 paint.setColor(Color.YELLOW); // 使用画笔在画布上画一个矩形(距左,上,右边距左,下边距上) Rect rect = new Rect(150, 150, 400, 400); canvas.drawRect(rect, paint); // 作弧形 paint.setColor(Color.RED); RectF rect2= new RectF(200,200,600,600); // (相对的矩形,起始度数,移动度数,是否使用画笔,和画笔) canvas.drawArc(rect2,0,120,false,paint); paint.setColor(Color.BLACK); // 线条宽度 paint.setStrokeWidth(20); canvas.drawLine(100,100,500,500,paint); // paint作文字 paint.setColor(Color.GREEN); paint.setTextSize(200); canvas.drawText("FUCK",100,300,paint); // bitmap放入到imageView ImageView imageView = (ImageView) findViewById(R.id.imageview); imageView.setImageBitmap(bitmap); } }
አֵ
相关文章推荐
- HTML5调用摄像头实例
- Canvas 在高清屏下绘制图片变模糊的解决方法
- flex 控件的重要属性
- 学习Winform文本类控件(Label、Button、TextBox)
- Delphi控件ListView的属性及使用方法详解
- web下载的ActiveX控件自动更新
- WinForm实现按名称递归查找控件的方法
- C#中父窗口和子窗口之间控件互操作实例
- C#编写ActiveX网页截图控件
- Android编程之Button控件用法实例分析
- Android控件之CheckBox、RadioButton用法实例分析
- 在Android开发中使用自定义组合控件的例子
- 一款超酷的Android自定义加载控件
- Android重写View实现全新的控件
- MFC中动态创建控件以及事件响应实现方法
- WinForm自定义函数FindControl实现按名称查找控件
- Android控件之ProgressBar用法实例分析
- WinForm拖拽控件生成副本的解决方法
- ASP.NET动态添加用户控件的方法
- WinForm遍历窗体所有子控件的方法