【问题标题】:How to move a bitmap (like long green grass moving by the wind) fixing its pivot at the bottom center point of the bitmap in android?如何移动位图(如随风移动的长长的绿草)将其枢轴固定在android中位图的底部中心点?
【发布时间】:2014-12-02 09:53:23
【问题描述】:

在我的应用程序中,我有一个长长的绿草位图。我必须修复位图,使其底部不会移动,它应该放在屏幕的左下角。所以我必须修复它枢轴在位图的底部中心。之后我应该将位图(如随风移动的草)向左移动一些像素,向右移动一些像素距离。但是位图不应该移动它的枢轴位置。我我无法固定枢轴位置并实现草的移动。我发布了我已经完成的代码。请帮我解决这个问题。

        private float direction = 1;
          private float mangle = 0;
  Bitmap green_1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.green_1);

      private void drawPaper(Canvas canvas){    
      Paint paint=new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);

        if (mangle >= 3) {
            direction=-0.2f;
        } else if (mangle<=-3) {
            direction=0.2f;
        }
        mangle = mangle + direction;

        Matrix matrix = new Matrix();
        matrix.postTranslate(0,heightOfCanvas-green_1.getHeight());
        matrix.postTranslate(0, mangle);


        canvas.drawBitmap(green_1, matrix, paint);
       }        

提前致谢。

【问题讨论】:

    标签: android bitmap rotation


    【解决方案1】:

    只需使用:旋转画布:

    canvas.rotate(deg, xpivot, ypivot)
    

    见:Canvas#rotate(float, float, float)

    【讨论】:

    • 我试过了,但无法得到它。如果可能的话,你能告诉我我的书面代码中的变化
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    相关资源
    最近更新 更多