使用camera、matrix仿即刻APP换一换

来源:互联网 发布:控制台运行java程序 编辑:程序博客网 时间:2024/05/01 06:51
 @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        //画当前图片        camera.save();        camera.rotateX(0);        camera.getMatrix(matrix);        camera.restore();        matrix.preTranslate(-width, 0);        matrix.postTranslate(width, offsetY);        canvas.drawBitmap(currentBitmap, matrix, null);        //画下一张图片        camera.save();        camera.rotateX(0);        camera.getMatrix(matrix);        camera.restore();        matrix.preTranslate(-width , -height);        matrix.postTranslate(width, offsetY);        canvas.drawBitmap(nextBitmap, matrix, null);    }

图片缩放

private Bitmap scaleBitmap(Bitmap bitmap) {        int originHeight = bitmap.getHeight();        Log.d("originHeight", originHeight + "");        int originWidth = bitmap.getWidth();        float scaleWidth = ((float) width)/ originWidth;        float scaleHeight = ((float) height)/ originHeight;        Matrix matrix = new Matrix();        matrix.postScale(scaleWidth, scaleHeight);        return Bitmap.createBitmap(bitmap, 0, 0, originWidth, originHeight, matrix, false);    }

属性动画

 public void changePic(Bitmap bitmap) {        currentBitmap = nextBitmap;        nextBitmap = scaleBitmap(bitmap);        ValueAnimator animator = ObjectAnimator.ofFloat(0, height);        animator.setDuration(1000);        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {            @Override            public void onAnimationUpdate(ValueAnimator animation) {                offsetY = (float) animation.getAnimatedValue();                postInvalidate();            }        });        animator.start();    }
0 0
原创粉丝点击