View and SurfaceView draw images, access not see the picture from the SurfaceView

- Why not get a picture from the SurfaceView - https://www.jianshu.com/p/05a8f7e1dd3d
Normal View generated pictures of principle, view.getDrawingCache ()
public Bitmap getBitmapFromView (View View) {
    IF (View == null ) {
        return null;
    }
    
    view.setDrawingCacheEnabled (to true);
    Bitmap Bitmap = Bitmap.createBitmap (view.getDrawingCache ());
    view.setDrawingCacheEnabled (to false);
    view.destroyDrawingCache ();
    
    return Bitmap;
}

 View general principle is to generate an image, create a new Bitmap, this new Bitmap set to a Canvas, and then call the Draw method Source View, the prototype will draw the image onto the new Bitmap. Simply put, it is through the Canvas View of the source image to a new Bitmap prototype drawing, so save up and then get a new Bitmap image of View.

  Drawing a two-dimensional image Android need four basic components:
. 1, A Bitmap: save image data of the pixel (to HOLD The pixels)
2, the Canvas A: a method comprising a series of drawing and image conversion (to host the draw calls, The Bitmap INTO Writing)
. 3, A primitive drawing: image prototype (EG Rect, the Path, text, Bitmap)
. 4, A Paint: drawing color pen description, style (to describe the colors and styles for the drawing)
phrase to describe: canvas prototype with a brush to the image drawn on bitmap.

  View and SurfaceView draw an image on, all they have in common is the use canvas to draw images. The difference is that ordinary View is obtained from a rewritable onDraw (Canvas canvas) of the canvas to the method, and is acquired SurfaceView canvas drawn in from the surface.

Guess you like

Origin blog.csdn.net/ShareUs/article/details/89842927