canvas对象需要借助view、surfaceview这样的载体来绘制

解决方案 »

  1.   

     * The Canvas class holds the "draw" calls. To draw something, you need
     * 4 basic components: A Bitmap to hold the pixels, a Canvas to host
     * the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect,
     * Path, text, Bitmap), and a paint (to describe the colors and styles for the
     * drawing).直接查看Canvas的说明,可以看到Canvas绘图的四要素(一个位图,一个画布,要画的东西和画刷)
    所以,其实你也可以再位图上绘制。但是想输出到屏幕,最终还是要借用View等对象        Bitmap bmp = Bitmap.createBitmap(100,100, Bitmap.Config.ARGB_8888);
            Paint paint = new Paint();
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.FILL);
            Canvas canvas = new Canvas(bmp);
            canvas.drawCircle(50,50,50,paint);
            canvas = null;
            ImageView imageView = (ImageView) findViewById(R.id.imageView2);
            imageView.setImageBitmap(bmp);
      

  2.   

    也就是说,无法自己canvas.draw(bitmap,matrix,null),那样用?必须要结合用VIEW来调用才行?
      

  3.   


    也就是说,无法自己canvas.draw(bitmap,matrix,null),那样用?必须要结合用VIEW来调用才行?
      

  4.   

    Canvas是系统创建的,并传递到系统Graphics的渲染调用流程中去。
    你自定义Canvas的话,系统怎么去使用你的类? 除非你修改Android的framewoks。