-------Activity.java

File f = new File("/sdcard/qianming.jpg");
   FileOutputStream fos = null;
   try {
    fos = new FileOutputStream(f);
    dv.cacheBitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
   
   } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

--------------DrawView.java

float preX;
float preY;
private Path path;
public Paint paint = null;
final int VIEW_WIDTH = 1024;
final int VIEW_HEIGHT = 1024;
// 定义一个内存中的图片,该图片将作为缓冲区
Bitmap cacheBitmap = null;
// 定义cacheBitmap上的Canvas对象
Canvas cacheCanvas = null;

public DrawView(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub
  cacheBitmap = Bitmap.createBitmap(VIEW_WIDTH, VIEW_HEIGHT,
    Config.ARGB_8888);
  cacheCanvas = new Canvas();
  path = new Path();
  // 设置cacheCanvas将会绘制到内存中的cacheBitmap上
  cacheCanvas.setBitmap(cacheBitmap);
  // 设置画笔的颜色
  paint = new Paint(Paint.DITHER_FLAG);
  paint.setColor(Color.RED);
  // 设置画笔风格
  paint.setStyle(Paint.Style.STROKE);
  paint.setStrokeWidth(4);
  // 反锯齿
  paint.setAntiAlias(true);
  paint.setDither(true);
  cacheCanvas.save(Canvas.ALL_SAVE_FLAG ); 
  cacheCanvas.restore();

}

Logo

openvela 操作系统专为 AIoT 领域量身定制,以轻量化、标准兼容、安全性和高度可扩展性为核心特点。openvela 以其卓越的技术优势,已成为众多物联网设备和 AI 硬件的技术首选,涵盖了智能手表、运动手环、智能音箱、耳机、智能家居设备以及机器人等多个领域。

更多推荐