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.

  • 相关阅读:
    php基本语法
    php的环境搭建
    Java数组及其内存分配
    最快的maven镜像
    配置maven到运行
    配置maven
    maven的eclise配置
    mysql中bit_count和bit_or函数的含义
    怎样查看MySQL是否区分大小写
    linux忘记mysql密码找回方法
  • 原文地址:https://www.cnblogs.com/slider/p/2993824.html
Copyright © 2011-2022 走看看