package com.example.android.apis.graphics;

23.TextAlign:

设置Path路径,贝赛尔曲线

1:  //设置Path路径
2:      private static void makePath(Path p) {
3:          p.moveTo(10, 0);
4:          p.cubicTo(100, -50, 200, 50, 300, 0);//贝赛尔曲线
5:      }

//mPos存的是字符串中每个字符的位置坐标

 1:  private float[] buildTextPositions(String text, float y, Paint paint) {
 2:          float[] widths = new float[text.length()];
 3:          // initially get the widths for each char
 4:          int n = paint.getTextWidths(text, widths);
 5:          // now popuplate the array, interleaving spaces for the Y values X值为字符的宽
 6:          float[] pos = new float[n * 2];
 7:          float accumulatedX = 0;
 8:          for (int i = 0; i < n; i++) {
 9:              pos[i * 2 + 0] = accumulatedX;
10:              pos[i * 2 + 1] = y;
11:              accumulatedX += widths[i];
12:          }
13:          return pos;
14:      }

onDraw()方法中:

1:  p.setColor(0x80FF0000);
2:              canvas.drawLine(x, y, x, y + DY * 3, p);//(x,y)为基准线
3:              p.setColor(Color.BLACK);
4:  
5:              canvas.translate(0, DY);
6:              p.setTextAlign(Paint.Align.LEFT);
7:              canvas.drawText(TEXT_L, x, y, p);//以(x,y)点Paint.Align.LEFT,画

1:  p.setColor(0xBB00FF00);
2:      for (int i = 0; i < pos.length / 2; i++) {
3:          canvas.drawLine(pos[i * 2 + 0], pos[i * 2 + 1] - DY, pos[i * 2 + 0],
4:              pos[i * 2 + 1] + DY * 2, p);
5:      }
6:      p.setColor(Color.BLACK);
7:  
8:      p.setTextAlign(Paint.Align.LEFT);
9:      canvas.drawPosText(POSTEXT, pos, p);

 1:  canvas.drawPath(mPath, mPathPaint);
 2:              p.setTextAlign(Paint.Align.LEFT);
 3:              canvas.drawTextOnPath(TEXTONPATH, mPath, 0, 0, p);
 4:  
 5:              canvas.translate(0, DY * 1.5f);
 6:              canvas.drawPath(mPath, mPathPaint);
 7:              p.setTextAlign(Paint.Align.CENTER);
 8:              canvas.drawTextOnPath(TEXTONPATH, mPath, 0, 0, p);
 9:  
10:              canvas.translate(0, DY * 1.5f);
11:              canvas.drawPath(mPath, mPathPaint);
12:              p.setTextAlign(Paint.Align.RIGHT);
13:              canvas.drawTextOnPath(TEXTONPATH, mPath, 0, 0, p);

24.Typefaces:

获得assets/fonts下的字体

1:  mFace = Typeface.createFromAsset(getContext().getAssets(),
2:              "fonts/samplefont.ttf");

onDraw()方法

1:  @Override
2:          protected void onDraw(Canvas canvas) {
3:              canvas.drawColor(Color.WHITE);
4:  
5:              mPaint.setTypeface(null);
6:              canvas.drawText("Default", 10, 100, mPaint);
7:              mPaint.setTypeface(mFace);
8:              canvas.drawText("Custom", 10, 200, mPaint);
9:          }

25.UnicodeChart:(没看)

26.Vertices:(没看) 触摸一下,图片走形

27.Xfermodes:

圆形画法:

1:  static Bitmap makeDst(int w, int h) {
2:          Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
3:          Canvas c = new Canvas(bm);
4:          Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
5:          p.setColor(0xFFFFCC44);
6:          c.drawOval(new RectF(0, 0, w * 3 / 4, h * 3 / 4), p);
7:          return bm;
8:      }

正方形的画法:

1:  static Bitmap makeSrc(int w, int h) {
2:          Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
3:          Canvas c = new Canvas(bm);
4:          Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
5:  
6:          p.setColor(0xFF66AAFF);
7:          c.drawRect(w / 3, h / 3, w * 19 / 20, h * 19 / 20, p);
8:          return bm;
9:      }

背景马塞克画法:

1:  Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
2:                  0xFFCCCCCC, 0xFFFFFFFF }, 2, 2, Bitmap.Config.RGB_565);
3:              mBG = new BitmapShader(bm, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
4:              Matrix m = new Matrix();
5:              m.setScale(6, 6);// 放大6倍
6:              mBG.setLocalMatrix(m);

Xfermode数组:

 1:  private static final Xfermode[] sModes = {
 2:              new PorterDuffXfermode(PorterDuff.Mode.CLEAR),
 3:              new PorterDuffXfermode(PorterDuff.Mode.SRC),
 4:              new PorterDuffXfermode(PorterDuff.Mode.DST),
 5:              new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER),
 6:              new PorterDuffXfermode(PorterDuff.Mode.DST_OVER),
 7:              new PorterDuffXfermode(PorterDuff.Mode.SRC_IN),
 8:              new PorterDuffXfermode(PorterDuff.Mode.DST_IN),
 9:              new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT),
10:              new PorterDuffXfermode(PorterDuff.Mode.DST_OUT),
11:              new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP),
12:              new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP),
13:              new PorterDuffXfermode(PorterDuff.Mode.XOR),
14:              new PorterDuffXfermode(PorterDuff.Mode.DARKEN),
15:              new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN),
16:              new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY),
17:              new PorterDuffXfermode(PorterDuff.Mode.SCREEN) };

onDraw()方法:

 1:  @Override
 2:          protected void onDraw(Canvas canvas) {
 3:              canvas.drawColor(Color.WHITE);
 4:  
 5:              Paint labelP = new Paint(Paint.ANTI_ALIAS_FLAG);
 6:              labelP.setTextAlign(Paint.Align.CENTER);
 7:  
 8:              Paint paint = new Paint();
 9:              paint.setFilterBitmap(false);
10:  
11:              canvas.translate(15, 35);
12:  
13:              int x = 0;
14:              int y = 0;
15:              for (int i = 0; i < sModes.length; i++) {
16:                  // draw the border
17:                  paint.setStyle(Paint.Style.STROKE);
18:                  paint.setShader(null);// Pass null to clear any previous shader
19:                  canvas.drawRect(x - 0.5f, y - 0.5f, x + W + 0.5f, y + H + 0.5f, paint);
20:  
21:                  // draw the checker-board pattern
22:                  paint.setStyle(Paint.Style.FILL);
23:                  paint.setShader(mBG);
24:                  canvas.drawRect(x, y, x + W, y + H, paint);
25:  
26:                  // draw the src/dst example into our offscreen bitmap
27:                  int sc = canvas.saveLayer(x, y, x + W, y + H, null,
28:                      Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG
29:                          | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
30:                          | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
31:                          | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
32:                  // canvas.save();
33:                  canvas.translate(x, y);
34:                  canvas.drawBitmap(mDstB, 0, 0, paint);
35:                  paint.setXfermode(sModes[i]);
36:                  canvas.drawBitmap(mSrcB, 0, 0, paint);
padding-bottom: 0px !important; line-height: 18px; background-color: #f7f7ff !important; margin: 0em; padding-left: 12px !important; padding-right: 0px !important; color  
分享到: VPLEX - EMC的RAC | VS代码片段(snippet)创作工具——Snippet ...
  • 2010-05-18 22:33
  • 浏览 1288
  • 评论(0)
  • 相关推荐
评论
发表评论

您还没有登录,请您登录后再发表评论

更多相关文章

  1. android 实现分享功能两种方法
  2. 再也不信网上流传的方法了!!android创建组件的真正写法!
  3. 转:Parcle
  4. Android(安卓)MultiDex 解析与使用
  5. Android(安卓)APP 把view试图显示在顶层
  6. Android缓存机制&一个缓存框架推荐
  7. Android(安卓)ANR介绍及分析ANR log信息的方法
  8. Button监听方式
  9. android应用去掉标题栏的方法

随机推荐

  1. Android代码混淆之ProGuard
  2. Android拖拽图片的实现
  3. android 中窗体溢出(android.view.WindowL
  4. Glide框架
  5. Android】Retrofit网络请求参数注解,@Path
  6. Android(安卓)反编译Apk得到Java源代码
  7. android开发积累3-android多线程操作
  8. 改变ProgressBar默认颜色
  9. Android(安卓)通用Dialog的写法
  10. IJKPlayer 实现视频播放业务