Since the system buffer space is insufficient or the queue is full, the solution to the operation on the socket cannot be performed

2022-12-26   ES  

  • Demand
    In SurfaceView or ordinary view, in each drawing cycle, we not only need to update the drawing of the Bitmap object in the View, but also hope that the Bitmap can use its own center point as the center of the center to rotate.
  • Solution
    Use Canvas’s DrawbitMap (bitmap bitmap, matrix matrix, paint paint) method. The most important thing is custom Matrix.
    code is as follows:

    /** 
      * Draw a spin to transform 
      * 
      * @param canvas
     * @param paint
     * @parambitmap 
      * Bit chart object 
      * @paramrotation 
      * Rotating degree 
      * @paramPOSX 
      * Position coordinates at Canvas 
      * @param posY
     */
    private void drawRotateBitmap(Canvas canvas, Paint paint, Bitmap bitmap,
            float rotation, float posX, float posY) {
        Matrix matrix = new Matrix();
        int offsetX = bitmap.getWidth() / 2;
        int offsetY = bitmap.getHeight() / 2;
        matrix.postTranslate(-offsetX, -offsetY);
        matrix.postRotate(rotation);
        matrix.postTranslate(posX + offsetX, posY + offsetY);
        canvas.drawBitmap(bitmap, matrix, paint);
    }

First, we move the bitmap half (half of XY) to the upper left corner, and then rotate the required degree. Finally move the Center back. Then move to the position coordinate (POSX, POSY). Note that the coordinates (POSX, POSY) are the points in the upper left corner of the map.

In addition, in order to make the rotation coherent, when the method is called:

rotation += 0.1f * (new Random().nextInt(20));
drawRotateBitmap(canvas, paint, bitmap, rotation, posX, posY);
  • More communication

Android Development Alliance QQ Group: 272209595

source

Related Posts

python2.7 and 3.5 dual versions coexist and the use of PIP

KMP algorithm-C/C ++ The

MAC configuration Flutter development environment to the first Flutter App

Python list commonly used operation The

Since the system buffer space is insufficient or the queue is full, the solution to the operation on the socket cannot be performed

Random Posts

Python, the difference between OS and SYS modules

Migration IP change address Modify the RELOCATE

Dynamic planning the longest public child sequence LCS

SpringBoot entry (1)

Install Kafka on Windows and Docker and start commands. Lin