首页 > 学院 > 开发设计 > 正文

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

2019-11-09 17:25:24
字体:
来源:转载
供稿:网友
@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(); }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表