Android: Rotation of image around the center

后端 未结 1 368
悲哀的现实
悲哀的现实 2021-01-13 20:06

I\'m trying to rotate an image around the center. This works generally using RotateAnimation, but I want to have it a bit faster. I\'m now using the SurfaceView pattern with

相关标签:
1条回答
  • 2021-01-13 20:36

    Find the center of the original image and for the new image and center using that:

    Matrix minMatrix = new Matrix();
    //height and width are set earlier.
    Bitmap minBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas minCanvas = new Canvas(minBitmap);
    
    int minwidth = bitmapMin.getWidth();  
    int minheight = bitmapMin.getHeight();
    int centrex = minwidth/2;
    int centrey = minheight/2;
    
    minMatrix.setRotate(mindegrees, centrex, centrey);
    Bitmap newmin = Bitmap.createBitmap(minBitmap, 0, 0, (int) minwidth, (int) minheight, minMatrix, true);
    
    minCanvas.drawBitmap(newmin, (centrex - newmin.getWidth()/2), (centrey - newmin.getHeight()/2), null);
    minCanvas.setBitmap(minBitmap);
    
    0 讨论(0)
提交回复
热议问题