Bitmap

2490阅读 0评论2015-11-27 luozhiyong131
分类:Android平台


点击(此处)折叠或打开

  1. package org.lxh.demo;
  2. import android.content.Context;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.graphics.Canvas;
  6. import android.graphics.Color;
  7. import android.graphics.Paint;
  8. import android.util.AttributeSet;
  9. import android.view.View;
  10. public class MyView extends View {
  11.     public MyView(Context context, AttributeSet attrs) {
  12.         super(context, attrs);
  13.     }
  14.     @Override
  15.     protected void onDraw(Canvas canvas) {        // 绘图
  16.         Bitmap bitmap = BitmapFactory.decodeResource(super.getResources(),
  17.                 R.drawable.android_mldn);
  18.         Paint paint = new Paint();
  19.         paint.setAntiAlias(true);             // 消除锯齿
  20.         canvas.drawBitmap(bitmap, 0, 0, paint);         // 画图
  21.         paint.setColor(Color.WHITE);         // 白色字体
  22.         paint.setTextSize(20);             // 定义字号
  23.         canvas.drawText("图片高度:" + bitmap.getHeight() + ",图片宽度:" + bitmap.getWidth(),
  24.                 10, bitmap.getHeight() + 20, paint);    // 输出文字
  25.     }
  26. }
041002_Bitmap.ppt
上一篇:View中的绘图
下一篇:Java 对象和类