zoukankan      html  css  js  c++  java
  • Draw with a Canvas

    When you're writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a Canvas. A Canvas works for you as a pretense, or interface, to the actual surface upon which your graphics will be drawn — it holds all of your "draw" calls. Via the Canvas, your drawing is actually performed upon an underlying Bitmap, which is placed into the window.

    In the event that you're drawing within the onDraw() callback method, the Canvas is provided for you and you need only place your drawing calls upon it. You can also acquire a Canvas fromSurfaceHolder.lockCanvas(), when dealing with a SurfaceView object. (Both of these scenarios are discussed in the following sections.) However, if you need to create a new Canvas, then you must define the Bitmap upon which drawing will actually be performed. The Bitmap is always required for a Canvas. You can set up a new Canvas like this:

    Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    //like c.drawable(xx,xx,xx.xx)
    return b;

    Now your Canvas will draw onto the defined Bitmap. After drawing upon it with the Canvas, you can then carry your Bitmap to another Canvas with one of the Canvas.drawBitmap(Bitmap,...) methods. It's recommended that you ultimately draw your final graphics through a Canvas offered to you byView.onDraw() or SurfaceHolder.lockCanvas() (see the following sections).

    The Canvas class has its own set of drawing methods that you can use, like drawBitmap(...),drawRect(...)drawText(...), and many more. Other classes that you might use also have draw()methods. For example, you'll probably have some Drawable objects that you want to put on the Canvas. Drawable has its own draw() method that takes your Canvas as an argument.

  • 相关阅读:
    tcpdump命令详解
    Python isdecimal()方法
    Python-Tkinter几何布局管理
    Python choice() 函数
    Python中的join()函数的用法
    PLSQL连接虚拟机中的Oracle数据库
    卸载oracle
    teradata学习
    teradata在虚拟机安装客户端sql Assistant
    oracle面试
  • 原文地址:https://www.cnblogs.com/slider/p/2993824.html
Copyright © 2011-2022 走看看