旋转图片本身 以及使用动画旋转

    /**
     * 动画旋转图片


 int degree;
        int i1 = 220 * i / target;
        boolean b = i1 >= 118;
        if (b)
            degree = i1 - 118;
        else
            degree = 118 - i1;

        LogUtil.util("swlMatch", "返回数据是degress:" + degree + "------" + 236 * i / target + "---" + i + "---" + target);
        RotateAnimation rotateAnimation = new RotateAnimation(0, b ? degree : -degree, RotateAnimation.RELATIVE_TO_SELF,
                0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.53f);
        rotateAnimation.setFillAfter(true);//保持旋转后原状
        mOrepoolYellowDot.setAnimation(rotateAnimation);


    /**
     * 使用矩阵对象 旋转
     *
     * @param imgView
     * @param integer
     * @param i
     */
    private void rotateBitmap(ImageView imgView, Integer integer, int i) {
        //加载需要操作的图片,这里是一张图片
        Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), i);
        int width = bitmapOrg.getWidth();
        int height = bitmapOrg.getHeight();
        //计算缩放率,新尺寸除原始尺寸
        // 创建操作图片用的matrix对象
        Matrix matrix = new Matrix();
        //旋转图片 动作
        matrix.postRotate(integer);
        // 创建新的图片
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
        ViewGroup.LayoutParams params = imgView.getLayoutParams();

        params.width = DensityUtil.dip2px(332);
        params.height = DensityUtil.dip2px(342);

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(params);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.ALIGN_PARENT_BOTTOM);
        lp.setMargins(0, 0, 0, -12);
        imgView.setLayoutParams(lp);

        imgView.setImageBitmap(resizedBitmap);
    }

猜你喜欢

转载自blog.csdn.net/qq_33143459/article/details/80746158